Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PerformanceEventTiming.interactionId #1069

Closed
sefeng211 opened this issue Sep 11, 2024 · 12 comments
Closed

PerformanceEventTiming.interactionId #1069

sefeng211 opened this issue Sep 11, 2024 · 12 comments

Comments

@sefeng211
Copy link
Member

sefeng211 commented Sep 11, 2024

Request for Mozilla Position on an Emerging Web Specification

Other information

@smaug----
Copy link
Collaborator

Is there some explanation what is the use case for this?

@sefeng211
Copy link
Member Author

@smaug----
Copy link
Collaborator

It is not very well defined what is a "user interaction".

@zcorpan zcorpan moved this from Unscreened to Needs assignees in standards-positions review Sep 12, 2024
@mmocny
Copy link

mmocny commented Oct 3, 2024

Hey folks, thank you for taking a look and providing feedback here!

The interactionID-explainer.md that Sean linked is an older document. I think it still does a good job summarizing the motivations, but not the latest details, and doesn't try to specify the semantics at all. We could update it, but I think that document is largely been obsoleted.


Let me take a stab at making a quick summary of things here:

Goal: A single "Interaction" should map to a single user "gesture" such as a Click, Tap, or Keypress.

  • Developers would like a simple way to measure Interaction Responsiveness in these terms, because thats what really matters to users.
  • interactionId is a label, which helps developers focus on the most critical event timings, and/or critical moments within the overall performance timeline
    • i.e. Beyond just looking at the literal Event Timings with interactionId, it's common to use find overlapping LoAF API entires, or custom User Timings, or even other Event Timings, etc, to paint a whole story together.
  • A single "Interaction" might cause any number of distinct events.
    • Some events are contextual. For example, beforeinput, input, change...
    • Some events are not "Interactions". For example, pointerenter, pointerexit...
    • Some events are conditionally "Interactions". For example, pointerdown might become a scroll or a tap, or a drag. You have to wait and see. We differentiate by checking if pointercancel follows.
      • FYI: Event Timing API already needs to do this for first-input event timing. I just tested FF nightly and it already works.
    • Event Timing API filters out a lot of events (e.g. due to minimum durationThreshold) even when these are observed by the browser internally.

Net/net, its not possible for a developer to just figure this out using the raw Event Timing API, but it is relatively easy for the Event Timing API to do it internally (as it already needs to observe these events) and expose hints via interactionId.

How?

  • a new unique interactionId is assigned to each Event Timing that was involved in a shared user gesture, which we consider to be a new unique "Interaction". Typically there will be multiple events for a single interactionId.
  • Pointer events already have pointer_id, and keyboard events already have key_codes, which already go a long way to helping group interactions.
  • A single pointer_id or key_code can of course be the source of many distinct interactions over time. You can detect this by looking at the flow of events (i.e. new pointerdown or new keydown).
  • The order of events that gets dispatched is fairly well specified, and the Event Timing spec already has a published algorithm for how to compute interaction id out of the stream of event timings, which it already observes.

In full transparency, the Chromium implementation has gone through some iteration over the last year as we discovered various details. Much of this is just internal complexity, but I do think it would be worthwhile for me to audit and update the Event Timing spec to document the latest implementation updates in Chromium, in case we have deviated and/or need to add extra clarity. (I.e. cases like composition events for virtual keyboards)

I would love to work with @sefeng211 (I assume?) to make sure this matches FF behaviour well.

Also, eventually, we might want to consider moving the specification of this concept up out of Event Timing and into e.g. UI Events spec itself (See: w3c/event-timing#114, w3c/event-timing#49). Then we can leave the Event Timing as just measuring and reporting rather than also defining.


There have been many other docs published that summarize motivations, and summarize some developer feedback, for example:

@smaug----
Copy link
Collaborator

Click is not a user interaction. Click is an event dispatch based on (mouse/pointer)down/up events, or keypress. The draft probably needs some work.

@mmocny
Copy link

mmocny commented Oct 8, 2024

(I meant clicking on a physical mouse, which generates a stream of events, rather than just the click event type.)

@smaug----
Copy link
Collaborator

Right, but the draft spec talks about click event.

@mmocny
Copy link

mmocny commented Oct 8, 2024

Hey @smaug---- I might be misinterpretting your feedback, apologies if so.

Let me try one more time to clarify:

Event Timing spec modifies DOM event dispatch algorithm where we add a call to compute interactionID and then use that to initialize event timing. The finalize event timing steps also include some handling for interactionID (potentially that could be refactored a bit).

The following event types are are currently specced as involved in computing interactionID:

  • pointerdown
  • pointerup
  • pointercancel
  • keydown
  • keyup
  • compositionstart
  • input
  • click

...with clear steps for how a flow of events maps to new interaction ids.

Some of those events are not themselves assigned an interactionId but are used to determine if other events do get one.


In Chromium we currently found it useful to observe the following stream of events in practice, in addition to the above:

  • contextmenu (in chromium we found we don't dispatch pointercancel in this case)
  • keypress (this might just be internal chromium detail, as input should suffice)
  • compositionupdate
  • compositionend (these helped assign ids in certain IME input cases)

I haven't audited to know if the above are chromium specific, due to existing event dispatch warts, or if the spec should be updated.

@smaug----
Copy link
Collaborator

So chromium is not following the current spec if it follows only some of the events? Why does it have different behavior than the spec draft?

@mmocny
Copy link

mmocny commented Oct 15, 2024

So chromium is not following the current spec if it follows only some of the events?

It follows all the events currently in the spec. We additionally found that observing a small number of extra events helped disambiguate some cases and/or improve metrics reporting in small ways.

Why does it have different behavior than the spec draft?

This is not a desired gap. We should update draft spec (or chromium implementation), and I can try to do that. (I will take your feedback as a signal to prioritize that work.)

FWIW, most of the changes are minor (such as contextmenu being an alternative to pointercancel because we learned that pointer events don't dispatch pointercancel for that use case). This doesn't change the api, or even the types of events which expose interactionId, just clarifies the mechanism used to define interactions.

@mmocny
Copy link

mmocny commented Oct 15, 2024

Also: related to interactionId is interactionCount which is just a count of unique interactions.

Event Timing already has eventCounts which Mozilla implements, but a distinct interactionCount is needed for similar reasons to why interactionId is needed, to augment raw event timings / aggregate counts.

@smaug----
Copy link
Collaborator

I think we could be positive on this, but the spec needs tweaks so that implementations can be interoperable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs proposed position
Development

No branches or pull requests

4 participants