Closed Bug 1934683 Opened 1 year ago Closed 1 year ago

Implement PerformanceEventTiming.interactionId (needed for INP, i.e. "interaction-to-next-paint")

Categories

(Core :: DOM: Performance APIs, task)

task

Tracking

()

RESOLVED FIXED
138 Branch
Tracking Status
firefox138 --- fixed

People

(Reporter: sefeng211, Assigned: canova)

References

Details

(Keywords: dev-doc-complete)

Attachments

(4 external files)

Summary: Implement PerformanceEventTiming.interactionId → Implement PerformanceEventTiming.interactionId (needed for INP, i.e. "interaction-to-next-paint")

This patch tries to follow the spec as much as possible. But unfortunately this
wasn't enough to pass all the web-platform tests and there were some issues
in the spec logic.

I'm adding the fixes to various issues in the following patches, to easily see
what needs to be updated in the spec. Please see the following patches.

Spec: https://www.w3.org/TR/event-timing/#sec-computing-interactionid

Update on the work:

I experimented with implementing the interactionId. After directly following the spec, it didn't work correctly and had some issues. That's why I had to change the algorithm to make it work. But this means that the spec is incorrect/inaccurate. I have filed various issues in the spec to address these:

And from bug 1948647:

Assignee: nobody → canaltinova
Status: NEW → ASSIGNED
Attachment #9467740 - Attachment description: WIP: Bug 1934683 - Implement interactionId for PerformanceEventTiming directly from the spec → Bug 1934683 - Implement interactionId for PerformanceEventTiming directly from the spec r?sefeng
Attachment #9467743 - Attachment description: WIP: Bug 1934683 - Not in the spec: Changes on the event timing dispatch logic → Bug 1934683 - Changes on the performance event timing dispatch logic r?sefeng
Attachment #9467748 - Attachment description: WIP: Bug 1934683 - Not in the spec: Set interactionId of first-input correctly → Bug 1934683 - Move the first-input and event count logic to later dispatch r?sefeng
Attachment #9467751 - Attachment description: WIP: Bug 1934683 - Not in the spec: Set keydown interactionId to the simulated key click → Bug 1934683 - Set keydown interactionId to the simulated key click r?sefeng

Filed another spec bug about the keypress event: https://github.com/w3c/event-timing/issues/149

Attachment #9467748 - Attachment description: Bug 1934683 - Move the first-input and event count logic to later dispatch r?sefeng → Bug 1934683 - Move the first-input and event count logic to later dispatch and simplify it r?sefeng

This should be documented at https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Experimental_features.

I'm just wondering why the fine-grained pref name dom.performance.event_timing.enable_interactionid is chosen. Shouldn't this be behind a more general dom.performance.interaction_to_next_paint.enabled pref? Or is this specific API meant to ship independently from the rest of the INP implementation?

Sebastian

Flags: needinfo?(canaltinova)
Keywords: dev-doc-needed

"Interaction to Next Paint" metric is not part of the W3C Event Timing spec. INP is computed by using PerformanceEventTiming.interactionId. So once this interactionId is landed, libraries like Core Web Vitals will be able to calculate the INP value.

If you are curious, this is a simplified version of how INP is calculated:

let maxDurations = {};
new PerformanceObserver(list => {
    for (let entry of list.getEntries()) {
        if (entry.interactionId > 0) {
            let id = entry.interactionId;
            if (!maxDurations[id]) {
                maxDurations[id] = entry.duration;
            } else {
                maxDurations[id] = Math.max(maxDurations[id], entry.duration);
            }
        }
    }
}).observe({ type: 'event', buffered: true, durationThreshold: 16 }) ;
// Then aggregate `maxDurations` and report to analytics.

As you can see, we use entry.interactionId to calculate INP. Since we are not implementing the "Interaction to Next Paint" metric directly inside Firefox, it doesn't make sense to name the pref that way.

Flags: needinfo?(canaltinova)
Pushed by canaltinova@gmail.com: https://hg.mozilla.org/integration/autoland/rev/37a93b5fec30 Implement interactionId for PerformanceEventTiming directly from the spec r=sefeng,webidl,smaug https://hg.mozilla.org/integration/autoland/rev/385377fb3e05 Changes on the performance event timing dispatch logic r=sefeng https://hg.mozilla.org/integration/autoland/rev/f34b842adbcf Move the first-input and event count logic to later dispatch and simplify it r=sefeng https://hg.mozilla.org/integration/autoland/rev/3f9fd0de6a6c Set keydown interactionId to the simulated key click r=sefeng
Blocks: 1956574
Blocks: 1956809
Blocks: 1957012
Regressions: 1957607

MDN FF138 work for this tracked in https://github.com/mdn/content/issues/38885 - essentially addition of flag to compatibility data and info to the experimental features page.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: