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: cap byte-efficiency-audit scores to a max of 1 #14921

Merged
merged 1 commit into from
Mar 22, 2023
Merged

Conversation

brendankenny
Copy link
Member

Sometimes enacting an opportunity could actually regress performance and its audit could measure a negative wastedMs/overallSavingsMs. It turns out byte-efficiency-audit doesn't have any guard against this case and gives those results a score greater than 1, which triggers an out-of-range score error, and so what should be a passing result turns into an audit error.

This PR caps the byte-efficiency-audit score so negative savings still max out at a score of 1 and returns in a valid audit result.

For context, this doesn't happen often, e.g. ~0.09% for prioritize-lcp-image in the last HTTP Archive run and similar rates for the other byte-efficiency-audits, but obviously important to get right.

@brendankenny brendankenny requested a review from a team as a code owner March 22, 2023 21:28
@brendankenny brendankenny requested review from adamraine and removed request for a team March 22, 2023 21:28
Comment on lines +219 to +220
// `wastedMs` may be negative, if making the opportunity change could be detrimental.
// This is useful information in the LHR and should be preserved.
Copy link
Member Author

Choose a reason for hiding this comment

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

added this comment because my first thought was "why isn't wastedMs being passed through a Math.max(0, wastedMs)?", but it's actually very useful information to know that the opportunity would be negative, so I wanted to make that explicit to future readers of the code. Happy to move/bikeshed.

Comment on lines +147 to +148
assert.ok(negativeResult.numericValue < 0);
assert.equal(negativeResult.numericValue, negativeResult.details.overallSavingsMs);
Copy link
Member Author

Choose a reason for hiding this comment

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

explicit test asserting that we want the negative result in the LHR even though it won't appear in the HTML report once it's tucked into the passing audits section (displayValue is used then)

@@ -398,4 +409,19 @@ describe('Byte efficiency base audit', () => {
const result = await MockAudit.audit(artifacts, {settings, computedCache});
expect(result.details.overallSavingsMs).toBeCloseTo(575, 1);
});

describe('#scoreForWastedMs', () => {
Copy link
Member Author

@brendankenny brendankenny Mar 22, 2023

Choose a reason for hiding this comment

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

scoreForWastedMs is imported and used independently of audits extending ByteEfficiencyAudit in at least prioritize-lcp-image, so it felt worth it to test separately as well.

(there's one wastedMs assertion for every segment and every control point in the piecewise scoring function)

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.

3 participants