You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"first-input" dispatch logic doesn't update the interactionId of pointerdown entries #146
I filed another issue related to this algorithm in #142. But this issue is different, it's specifically about the interactionId.
While we are getting the pending pointer down value for the "first-input", we have this:
If window’s has dispatched input event is false, run the following steps:
If name is "pointerdown", run the following steps:
Set window’s pending first pointer down to a copy of timingEntry.
Set the entryType of window’s pending first pointer down to "first-input".
Notice the wording: "copy of timingEntry". So since this algorithm is being run before we know the interactionId of pointerdown entries, the copy of that entry will contain no interactionId.
Later once we see the pointerup and dispatch it, it will still not contain an interactionId, because this is a copy of that pointerdown entry, so any changes to the initial entry will not be affected.
Looking at Chromium's code, I see that there is a special case inside pointerup that actually updates the interactionId of the copied pointerdown entry:
So we should have the same update mechanism in the spec to make sure that the interactionId of a "first-input" comes from the pointerup and it is present.
As per #145, I think that after those changes we can more the first-input checks to be part of the "dispatch" steps, rather than during the "compute" steps. Since we wont dispatch until after all the attributes of the Entry are known, we won't need to special case this any more?
Hmm, already "first-input" checks are in the dispatch step, isn't it?
Ah, but I think I see what you mean. Currently in this patch, I'm doing this during dispatch step (search for PerformanceMainThread::DispatchPendingEventTimingEntries):
Loop over the "entries to be queued":
Assign their "duration" if it's not assigned yet.
Increment event count
Do the "first-input" computation.
Check if all entries have "known interactionIds".
If all entries have known interactionIds:
Loop over them again and dispatch them.
So essentially it's split into 2 loops. But I think you use a different mechanism to determine the duration (with the paintTime). So probably you don't set the duration there. It means that you can remove the first loop and move everything to the second.
But I can also do that in my patch. I can only keep 1. and 4. in the first loop, and move 2. and 3. to the second. This would indeed fix this issue where we didn't know the pointerdown's interactionId.
However, per spec I don't think we need to define that first loop-- each event could be defined to measures its own next paint and set its own duration, as part of event dispatch. (The loop in chromium is really just to help group related timings together and could have been omitted if each event asked for its own paint timing).
Ah I see. I think inside of that method in the second link, this std::all_of is like my first loop (minus setting the duration and early return from all_of). And the second loop happens in this std::for_each.
However, per spec I don't think we need to define that first loop-- each event could be defined to measures its own next paint and set its own duration, as part of event dispatch. (The loop in chromium is really just to help group related timings together and could have been omitted if each event asked for its own paint timing).
Hmm, currently, per spec, "dispatch pending Event Timing entries" step happens in the HTML spec, inside the " event loop processing model". I think this is because we want to get the endTime/renderTime from this area, so we can set the duration.
I guess this is different in Chromium, because it's using the paintTime and not really the renderTime. But I think next paint is a bit vague and keeping this spec interoperable between browsers is important. So I'm not so sure what to do there.
Also. another question: You seem to chunk up the "entries to be queued" by their presentation_index, while dispatching. What is the presentation_index exactly? I guess it's not something that changes the behavior, but wanted to be sure.
So in the event loop processing model (some of this spec has been refactored over time) we used to have a simple set of steps:
Run a task
Update the rendering
So, when you "ran a task" to dispatch events, you could just wait to measure the rendering steps.
But in practice browsers like chromium and Gecko (AFAIK) will not schedule rendering opportunities for each turn of the event loop and you can have multiple tasks with many events (and each task can be multiple events), so eventually you have a single update-the-rendering which finally finishes the event timings and can assign paint timings / duration. (The spec for Event Timing hasn't been updated to leverage PaintTimingMixin from Paint Timing API but several specs have done so and I think Event Timing should-- since this cleans up the language for how to do this).
So in Chromium we could have every single event timing ask for the "next paint time", but instead we just do this from the first new event per animation frame, and then group other events together. Its like a small micro optimization because we prefer not to have a lot of observer calls for presentation timing (which is cross-thread boundary) though honestly I dont know if its even that critical.
Another reason we group is just because it help us with lab-tracing and field metrics, since we've learned that reporting "long animation frames" and "events per animation frame" is the most useful for diagnosing, rather than measuring each event in isolation.
I filed a bug for PaintTimingMixin in Firefox here a few days ago. Currently we don't have support it, but it would be good to implement eventually.
I agree that we should use PaintTimingMixin here as well. My first iteration is not using that, and still using the current behavior mentioned in the spec. My first implementation will not leverage this mixin as the first step.
I see, thanks for mentioning the reasoning behind grouping. But I'm still not so sure if there could be more than one group per dispatch in reality. Because I think you call the dispatch method (WindowPerformance::ReportEventTimings), on OnPresentationPromiseResolved which is I think waiting for a single presentation and then reporting the event timing. So it should be one dispatch per presentation and presentation_index, right? But I haven't checked the whole code very carefully, I might be missing something.
On the other hand, for the spec: Would you be okay to check every single item in the "entries to be queued" to have duration+interactionId instead of chunking them up? I think it's easier that way.
Activity
mmocny commentedon Feb 24, 2025
As per #145, I think that after those changes we can more the first-input checks to be part of the "dispatch" steps, rather than during the "compute" steps. Since we wont dispatch until after all the attributes of the Entry are known, we won't need to special case this any more?
WDYT?
canova commentedon Feb 24, 2025
Hmm, already "first-input" checks are in the dispatch step, isn't it?
Ah, but I think I see what you mean. Currently in this patch, I'm doing this during dispatch step (search for
PerformanceMainThread::DispatchPendingEventTimingEntries):So essentially it's split into 2 loops. But I think you use a different mechanism to determine the duration (with the
paintTime). So probably you don't set the duration there. It means that you can remove the first loop and move everything to the second.But I can also do that in my patch. I can only keep 1. and 4. in the first loop, and move 2. and 3. to the second. This would indeed fix this issue where we didn't know the pointerdown's
interactionId.mmocny commentedon Feb 25, 2025
Exactly!
We actually do sort-of have two loops, in that we have a loop for assigning duration (based on events which are painted together) and then a loop for actually dispatching.
However, per spec I don't think we need to define that first loop-- each event could be defined to measures its own next paint and set its own duration, as part of event dispatch. (The loop in chromium is really just to help group related timings together and could have been omitted if each event asked for its own paint timing).
canova commentedon Feb 25, 2025
Ah I see. I think inside of that method in the second link, this
std::all_ofis like my first loop (minus setting the duration and early return fromall_of). And the second loop happens in thisstd::for_each.Hmm, currently, per spec, "dispatch pending Event Timing entries" step happens in the HTML spec, inside the " event loop processing model". I think this is because we want to get the
endTime/renderTimefrom this area, so we can set theduration.I guess this is different in Chromium, because it's using the
paintTimeand not really therenderTime. But I think next paint is a bit vague and keeping this spec interoperable between browsers is important. So I'm not so sure what to do there.canova commentedon Feb 25, 2025
Also. another question: You seem to chunk up the "entries to be queued" by their presentation_index, while dispatching. What is the presentation_index exactly? I guess it's not something that changes the behavior, but wanted to be sure.
mmocny commentedon Feb 25, 2025
So in the event loop processing model (some of this spec has been refactored over time) we used to have a simple set of steps:
So, when you "ran a task" to dispatch events, you could just wait to measure the rendering steps.
But in practice browsers like chromium and Gecko (AFAIK) will not schedule rendering opportunities for each turn of the event loop and you can have multiple tasks with many events (and each task can be multiple events), so eventually you have a single update-the-rendering which finally finishes the event timings and can assign paint timings / duration. (The spec for Event Timing hasn't been updated to leverage
PaintTimingMixinfrom Paint Timing API but several specs have done so and I think Event Timing should-- since this cleans up the language for how to do this).So in Chromium we could have every single event timing ask for the "next paint time", but instead we just do this from the first new event per animation frame, and then group other events together. Its like a small micro optimization because we prefer not to have a lot of observer calls for presentation timing (which is cross-thread boundary) though honestly I dont know if its even that critical.
Another reason we group is just because it help us with lab-tracing and field metrics, since we've learned that reporting "long animation frames" and "events per animation frame" is the most useful for diagnosing, rather than measuring each event in isolation.
canova commentedon Feb 26, 2025
I filed a bug for
PaintTimingMixinin Firefox here a few days ago. Currently we don't have support it, but it would be good to implement eventually.I agree that we should use
PaintTimingMixinhere as well. My first iteration is not using that, and still using the current behavior mentioned in the spec. My first implementation will not leverage this mixin as the first step.I see, thanks for mentioning the reasoning behind grouping. But I'm still not so sure if there could be more than one group per dispatch in reality. Because I think you call the dispatch method (
WindowPerformance::ReportEventTimings), onOnPresentationPromiseResolvedwhich is I think waiting for a single presentation and then reporting the event timing. So it should be one dispatch per presentation andpresentation_index, right? But I haven't checked the whole code very carefully, I might be missing something.On the other hand, for the spec: Would you be okay to check every single item in the "entries to be queued" to have duration+interactionId instead of chunking them up? I think it's easier that way.
Bug 1934683 - Move the first-input and event count logic to later dis…
Bug 1934683 - Move the first-input and event count logic to later dis…
Bug 1934683 - Move the first-input and event count logic to later dis…