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(lantern): fallback to FCP in 0-weight SI situations #11174

Merged
merged 2 commits into from
Jul 30, 2020

Conversation

patrickhulce
Copy link
Collaborator

Summary
I was finally able to reproduce #11154 and found the issue. In some circumstances in DevTools only under desktop throttling (i.e. no CPU throttling), we end up with no consequential layout events (this trace has a single layout event that lasted 1ms). Because we use the log magnitude, log 1 is 0 which can't be a denominator :)

Related Issues/PRs
fixes #11154

@patrickhulce patrickhulce requested a review from a team as a code owner July 28, 2020 20:48
@patrickhulce patrickhulce requested review from brendankenny and removed request for a team July 28, 2020 20:48
@patrickhulce patrickhulce changed the title core(lantern): fallback to FCP in 0-weight situations core(lantern): fallback to FCP in 0-weight SI situations Jul 28, 2020
const totalWeightedTime = layoutWeights
.map(evt => evt.weight * Math.max(evt.time, fcpTimeInMs))
.reduce((a, b) => a + b, 0);
const totalWeight = layoutWeights.map(evt => evt.weight).reduce((a, b) => a + b, 0);

if (!totalWeight) return fcpTimeInMs;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if layoutWeights.length === 0 then totalWeight will still be 0

@@ -23,7 +25,46 @@ describe('Metrics: Speed Index', () => {
timing: Math.round(result.timing),
optimistic: Math.round(result.optimisticEstimate.timeInMs),
pessimistic: Math.round(result.pessimisticEstimate.timeInMs),
}).toMatchSnapshot();
}).toMatchInlineSnapshot(`
Object {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we initially committed this snapshot before jest supported inline snapshots, which are greatly preferred for objects of this size to make the expectations more obvious and easier to notice

Copy link
Collaborator

Choose a reason for hiding this comment

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

aside: did jest mess with the format of the rest of the file? If so, could you try updating to the latest jest and see if they've fixed it? I know it was on their radar.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

prettier's API doesn't support it yet prettier/prettier#5807

it only affected the 1 line that would be updated on any future -u so didn't seem like a big deal 🤷‍♂️

Copy link
Collaborator

Choose a reason for hiding this comment

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

darn, still not done.

it's a much larger annoyance for other files, requiring you to either change dozens of other lines to prettier's standards, or copy and pasting the result -u, revert everything, and individually applying the new snapshot.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is, and I'd obvs love to adopt prettier even if it's only in our test files (looks around to see if @brendankenny is hiding in the tall grass), but some git checkout -p to clean it up definitely beats manually updating all the snapshot expectations :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

nice, didn't know checkout could do patches.

Copy link
Member

Choose a reason for hiding this comment

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

looks around to see if @brendankenny is hiding in the tall grass

🌾🌿 ⚔️ 🌿🌾

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM!

Just some clarifying questions and attempt to paint a bikeshed.

@@ -10,6 +10,8 @@ const assert = require('assert').strict;
const SpeedIndex = require('../../../computed/metrics/speed-index.js');
const trace = require('../../fixtures/traces/progressive-app-m60.json');
const devtoolsLog = require('../../fixtures/traces/progressive-app-m60.devtools.log.json');
const traceNaN = require('../../fixtures/traces/speedindex-nan-m84.trace.json');
const devtoolsLogNaN = require('../../fixtures/traces/speedindex-nan-m84.devtoolslog.json');
Copy link
Member

Choose a reason for hiding this comment

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

is there an alternate name for the trace/devtoolslog that says what the nan refers to? zero-ms-layouts or something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

speedindex-1ms-layout sgtm 👍

Object {
"optimistic": 575,
"pessimistic": 563,
"timing": 599,
Copy link
Member

Choose a reason for hiding this comment

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

is it worth asserting these are equal to the fcp estimates or should that be a non-guaranteed implementation detail and/or not worth adding any extra piping to be able to assert it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IMO, not worth it. conceptually speed index could be lower than FCP due to background color painting so if we ever decided to try to match that it wouldn't be an assertion that holds up.

const totalWeightedTime = layoutWeights
.map(evt => evt.weight * Math.max(evt.time, fcpTimeInMs))
.reduce((a, b) => a + b, 0);
const totalWeight = layoutWeights.map(evt => evt.weight).reduce((a, b) => a + b, 0);

if (!totalWeight) return fcpTimeInMs;
return totalWeightedTime / totalWeight;
Copy link
Member

Choose a reason for hiding this comment

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

it's hard to get my brain around possible values here without looking at a bunch of examples, but is it possible to get a weird discontinuity where adding a single layout task could give a result lower than fcpTimeInMs?

IOW, should this line be return Math.max(totalWeightedTime / totalWeight, fcpTimeInMs); or is that implicitly handled?

(this isn't something new, handling the division by zero case is 👍 )

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is it possible to get a weird discontinuity where adding a single layout task could give a result lower than fcpTimeInMs

no the .map(evt => evt.weight * Math.max(evt.time, fcpTimeInMs)) above should prevent any time earlier than fcpTimeInMs from being used in the weight

Copy link
Member

Choose a reason for hiding this comment

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

Oh, yep, there it is :)

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

Successfully merging this pull request may close these issues.

Invalid score for speed-index: NaN
5 participants