-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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(cls-all-frames): use weighted score from trace #12034
Conversation
const trace = require('../../fixtures/traces/frame-metrics-m89.json'); | ||
const devtoolsLog = require('../../fixtures/traces/frame-metrics-m89.devtools.log.json'); | ||
const trace = require('../../fixtures/traces/frame-metrics-m90.json'); | ||
const devtoolsLog = require('../../fixtures/traces/frame-metrics-m90.devtools.log.json'); |
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.
I tried to avoid changing our expectations for LCP-AF and FCP-AF in any tests that I could. This is the only place I couldn't.
@@ -0,0 +1,242 @@ | |||
{ |
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.
Keeping frame-metrics-m89.json
around so we don't have to change expectations for LCP-AF and FCP-AF everywhere.
@@ -3,7 +3,7 @@ | |||
exports[`Performance: metrics evaluates valid input (with lcp from all frames) correctly 1`] = ` | |||
Object { | |||
"cumulativeLayoutShift": 0.0011656245471340055, | |||
"cumulativeLayoutShiftAllFrames": 0.4591700003057729, | |||
"cumulativeLayoutShiftAllFrames": undefined, |
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.
This snapshot is using the old trace without the weighted score, so CLS-AF is undefined.
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.
LGTM just the throw decision outstanding I think :)
* @param {LH.TraceEvent} event | ||
* @return {event is LayoutShiftEvent} | ||
*/ | ||
static isLayoutShiftEvent(event) { |
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.
nit: isValidLayoutShiftEvent
or something? I wouldn't expect all of the validation and throw logic in a simple check
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.
I'm leaving this as is because the validation and throw logic are removed.
// Weighted score was added to the trace in m89: | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=1173139 | ||
if (typeof event.args.data.weighted_score_delta !== 'number') { | ||
throw new LHError( |
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.
should this fallback to score? seems like there's still some value in seeing if the all frames version and main-frame version are different. I understand the difficulty of figuring out which CLS values are valid, but seems like we're going to have to do that anyway with a mix of LH versions in the same month.
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.
I'm good with doing a fallback and replacing this with a log warning for now.
I'm just worried that the fallback doesn't make sense in the long run. Once we get through the churn of different LH and Chrome versions I would like to remove the fallback.
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.
SG, can throw a FIXME: remove after XX
on there :)
lighthouse-core/test/computed/metrics/cumulative-layout-shift-all-frames-test.js
Outdated
Show resolved
Hide resolved
@patrickhulce sorry to increase the scope a bit, but I noticed another pretty big error while picking through some HTTPArchive results. Many of the sites had a CLS-AF smaller than CLS which doesn't make sense since extra frames should only add to CLS. Turns out I didn't add the correct
I added changes in this PR to address this error. |
// ignored for CLS. Since we don't expect any user input, we add the score of these | ||
// shift events to CLS. | ||
// See https://bugs.chromium.org/p/chromium/issues/detail?id=1094974. | ||
for (const event of layoutShiftEvents) { |
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.
Some more comments here would be useful. Is this accurate?
We set the first initial events that appear as
had_recent_input=true
tofalse
, up until the first timehad_recent_input=false
appears. This ignores the incorrect inputs that are an artifact of Lighthouse changing the viewport size, and keeps any inputs that appear later in the page load (as a result of a puppeteer script controlling the page).
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.
does the logic here need to be more complex now in a multi-frame world? how does had_recent_input
affect subframes when their viewports are resized from js? should those actually be counted? if so, the "had_recent_input" name is really starting to stretch 😆
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.
+1 to everything above, plus should we be doing this fixup in trace-of-tab (well, trace-processor, actually)? Or not altering the original trace events and doing it on a copy of the LayoutShift events in each of these audits...otherwise the state of early LayoutShift events depends on what other audits/computed artifacts have already run (e.g. an ads plugin CLS audit that either has to know about this issue or has to only run after the perf audits to get the numbers right)
return /** @type {number} */ (e.args.data.score); | ||
if (e.args.data.had_recent_input) return 0; | ||
|
||
// FIXME: remove after 89 hits stable |
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.
@paulirish likes COMPAT
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 I guess this is more COMPAT than FIXME, sorry for the bad suggestion @adamraine
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.
Nice catch I completely forgot about that workaround too! We should probably share the computation of CLS based on a sequence of layoutshift events now that it's sufficiently complicated though. How disappointed would you be to move that fix and a sharing refactor to a new PR? Anytime there's logic requiring a comment that large, feels like it shouldn't be duplicated :)
Unrelated but important to note that we won't really have a similar workaround ability for FR :/ we'll cross that bridge when we get there I suppose.
// ignored for CLS. Since we don't expect any user input, we add the score of these | ||
// shift events to CLS. | ||
// See https://bugs.chromium.org/p/chromium/issues/detail?id=1094974. | ||
for (const event of layoutShiftEvents) { |
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.
does the logic here need to be more complex now in a multi-frame world? how does had_recent_input
affect subframes when their viewports are resized from js? should those actually be counted? if so, the "had_recent_input" name is really starting to stretch 😆
Ok, moving the |
Another update: release manager would prefer the weighted score change stay in M90: I don't think this is a major issue for us, just means we need to adjust some comments and stuff here. |
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.
still LGTM thanks for punting the other input fix :)
Closes #12023
CLS-AF will be calculated with
weighted_score_delta
instead ofscore
.I'm not planning on merging until after weighted score is merged in M89:https://bugs.chromium.org/p/chromium/issues/detail?id=1173139
Patch is not getting merged into M89, not waiting for M90 to merge this.