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

core(cumulative-layout-shift): introduce CDT's trace processor for CLS #15225

Closed
wants to merge 10 commits into from

Conversation

connorjclark
Copy link
Collaborator

  1. Pulls in CDT's trace processor via cdt-build-lib.js
  2. Uses the trace processor to calculate CLS. If it fails for whatever reason, falls back to our original implementation

@connorjclark connorjclark requested a review from a team as a code owner July 6, 2023 18:28
@connorjclark connorjclark requested review from brendankenny and removed request for a team July 6, 2023 18:28
});
// We really want the logic that getLayoutShiftEvents provides for filtering out
// some events based on recent input.
// Would it make sense to upstream this to CDT?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say yes. If we are going to unify our trace processors then we should avoid modifying the results.

Copy link
Collaborator Author

@connorjclark connorjclark Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jackfranklin does filtering out user-initiated layout shifts from perf panel sound good?

(we don't need to block this initial integration on this)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the perf panel we have historically shown shifts even if they were user initiated, but no reason that the handler couldn't expose the set of user initiated shifts and set of non-user initiated shifts, or something like that, so that any consumer can use whichever set they want.

core/gather/gatherers/source-maps.js Outdated Show resolved Hide resolved
@@ -113,6 +115,122 @@ const modifications = [
'Platform',
],
},
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this complexity melts away once we validate this shared trace processor approach, and extract to a shared library.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the optimal order of operations? I haven't seen the design discussions so far, but this requires a bunch of generation/generated code to do a task we already know both code bases can do (CLS is straightforward and they both have extensive CLS tests).

The shared library is what historically no one had a unified vision of and is going to require work that will need to stick around (e.g. making code living in DevTools importable). Does it make more sense to start there so the infrastructure won't have to melt away, it won't be needed from the start?

cumulativeLayoutShift = data.LayoutShifts.sessionMaxScore;
} catch (e) {
// Something failed, so fallback to our own implementation.
log.error('Error running SDK.TraceProcessor', e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this deserves to be captured in sentry. If there are situations where the DT trace processor breaks then we should investigate and fix them.

@@ -220,3 +338,9 @@ function writeGeneratedFile(outputPath, contents) {
}

modifications.forEach(doModification);
writeGeneratedFile(`${outDir}/models/trace/handlers/handlers.js`, `
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it just easier to rewrite this file? Can you add a comment about this?

@brendankenny
Copy link
Member

once we validate this shared trace processor approach, and extract to a shared library

is there a doc for this?

@jackfranklin
Copy link

is there a doc for this?

I will ping you on corp with some info, but there is not a definitive plan yet as really the idea with this PR was to validate the approach and that the architecture of this engine is suitable. I think the next step is to chat about what we really mean by "shared library" and think through how it would work in practice.

@connorjclark
Copy link
Collaborator Author

We're gonna import this from npm now, so closing!

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

Successfully merging this pull request may close these issues.

5 participants