Skip to content

"first-input" dispatch logic doesn't update the interactionId of pointerdown entries #146

Open

Description

@canova

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:

  1. If window’s has dispatched input event is false, run the following steps:
    1. If name is "pointerdown", run the following steps:
      1. Set window’s pending first pointer down to a copy of timingEntry.
      2. 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:

...
else if (event_timing_entry->name() == event_type_names::kPointerup &&
           first_pointer_down_event_timing_) {
  if (event_timing_entry->HasKnownInteractionID()) {
    first_pointer_down_event_timing_->SetInteractionIdAndOffset(
        event_timing_entry->interactionId(),
        event_timing_entry->interactionOffset());
  }
  DispatchFirstInputTiming(first_pointer_down_event_timing_);
}
...

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.


FWIW, I came across this issue while experimenting it in Firefox. I have some WIP patches in this bug, but after implementing the spec, I had to update this logic like this patch

Activity

  1. mmocny commented on Feb 24, 2025

    @mmocny
    Collaborator

    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?

  2. canova commented on Feb 24, 2025

    @canova
    MemberAuthor

    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):

    1. Loop over the "entries to be queued":
      1. Assign their "duration" if it's not assigned yet.
      2. Increment event count
      3. Do the "first-input" computation.
      4. Check if all entries have "known interactionIds".
    2. If all entries have known interactionIds:
      1. 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.

  3. mmocny commented on Feb 25, 2025

    @mmocny
    Collaborator

    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).

  4. self-assigned this
    on Feb 25, 2025
  5. canova commented on Feb 25, 2025

    @canova
    MemberAuthor

    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.

    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.

  6. canova commented on Feb 25, 2025

    @canova
    MemberAuthor

    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.

  7. mmocny commented on Feb 25, 2025

    @mmocny
    Collaborator

    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.

  8. canova commented on Feb 26, 2025

    @canova
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions