-
Notifications
You must be signed in to change notification settings - Fork 401
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
Refactor INP attribution code to fix errors on Windows 10 #495
Conversation
@@ -35,12 +35,13 @@ interface pendingEntriesGroup { | |||
startTime: DOMHighResTimeStamp; | |||
processingStart: DOMHighResTimeStamp; | |||
processingEnd: DOMHighResTimeStamp; | |||
renderTime: DOMHighResTimeStamp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically the code below could use group.entries[0].startTime + group.entries[0].duration
and not add a new property here, but it seemed better to put this here as a convenience
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, new property is better I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @brendankenny! Overall these changes LGTM andI think do simplify things.
@@ -35,12 +35,13 @@ interface pendingEntriesGroup { | |||
startTime: DOMHighResTimeStamp; | |||
processingStart: DOMHighResTimeStamp; | |||
processingEnd: DOMHighResTimeStamp; | |||
renderTime: DOMHighResTimeStamp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, new property is better I think.
// 2) occur after the most recently-processed event entry. | ||
const loafsToKeep: Set<PerformanceLongAnimationFrameTiming> = new Set(); | ||
pendingEntriesGroupMap.forEach((group) => { | ||
for (let i = 0; i < pendingEntriesGroups.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't like a forEach()
right above a regular for loop, eh? :)
You could alternatively do something like this to keep it one line (and which is common in the Google JS style guide):
for (let i = 0, group; group = pendingEntriesGroups[i]; i++) {
UPDATE (2024-06-20): while intended to just be an internal refactor, the changes in this PR do appear to fix the source of errors being thrown for some users on Windows 10. The cause of these errors is still unknown.
I wanted to do this while the code was still fresh in my mind. There are no expected functional changes here, just code simplification.
Currently,
previousRenderTimes
is used for easier lookup into event-timing-entry groups inpendingEntriesGroupMap
and for quick event grouping by render time, but it's also not quite the same set of render times inpendingEntriesGroupMap
(the times and groups grow together as events come in, but the map actually contains all the events referenceable bypreviousRenderTimes
and groups with events fromlongestInteractionList
). The results in more bookkeeping and (speaking as someone recently getting their head around this code :) it can make some of this logic harder to follow because effects aren't always collocated.This PR proposes getting rid of
previousRenderTimes
so that there are only two main data structures, an array tracking LoAFs and an array tracking groups of event timing entries. I think this makes it a little simpler to understand how events are grouped as they come in and which event groups are being preserved during cleanup, without a runtime or clarity tradeoff elsewhere.latestProcessingEnd
and the entry WeakMap are still here as secondary data sources because they're convenient ways to skip extra work and they're both only ever updated in a single place (the WeakMap now maps directly to entry groups, though).