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

refactor: DRY byte efficiency audits #1635

Merged
merged 12 commits into from
Feb 15, 2017
Merged

refactor: DRY byte efficiency audits #1635

merged 12 commits into from
Feb 15, 2017

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Feb 4, 2017

R: @pavelfeldman all

  • Moves the byte efficiency audits to their own folder
  • Creates a base audit class for byte efficiency audits to use
  • Sorts unused byte rows by their total savings in descending order (biggest bang for buck first)
  • Relaxes the thresholds for failure
    • CSS Usage will now only fail if at least 10ms would have been saved by eliminating the unused CSS
    • Optimized Images will now fail at 1MB total waste (up from 100k) or a JPEG wastes 25k (up from 1 byte) or an image would have saved 100k from conversion to WebP (up from 50k)
    • Responsive Images will only show images that are larger than their displayed size with DPR accounted for and will only fail if one of those images is 25k larger than necessary (changed from 10% of the pixels)

How it looks now

image
(CSS Usage is green because this was run without throttling and it wouldn't have saved at least 10ms)

Examples of Verge de-noising

Before
image
After
image

fixes #1612

The smokehouse tests will fail thanks to us ignoring negligible results now. Not sure if we can find an elegant way of lowering the threshold or we have to just use full-size examples in smokehouse.

@patrickhulce patrickhulce changed the title refactor: DRY byte efficiency tests refactor: DRY byte efficiency audits Feb 4, 2017
@ebidel
Copy link
Contributor

ebidel commented Feb 7, 2017

@patrickhulce this will need a rebase. Rebasing against the latest master will also pick up #1654.

@patrickhulce
Copy link
Collaborator Author

PTAL, I'll update smoke tests once there's general agreement on the more lax thresholds.

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.

I'm liking this. My only concern vs if this was just done with a helper function would be what happens when we get a byte efficiency audit that doesn't completely fit this mold (e.g. JS usage...we'd also want to report potential savings on compile/parse time) but I think this refactor leaves us in a good position to handle that, actually.

I haven't thought at all about the new thresholds so others will have to comment there :)

For smokehouse, it would be a shame to lose it for testing these audits. We probably do want to add some assets big enough to hit the thresholds, but replacing everything might be excessive.

One option (tell me if this is crazy) would be to add something to the extended info that doesn't end up in the table, so you'd still have value: {results, tableHeadings}, but also a negligibleResults or whatever property with the filtered out stuff. It would add noise (and size) to the raw results for results that ostensibly don't matter mostly just to make tests happy, so might not be worth it.


const KB_IN_BYTES = 1024;

class UnusedBytes extends Audit {
Copy link
Member

Choose a reason for hiding this comment

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

can you add a brief class description, basically this is the base class for byte efficiency audits, subclass and override audit_ to write your own?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do!

@patrickhulce
Copy link
Collaborator Author

Thanks for braving the scary diff @brendankenny! :)

what happens when we get a byte efficiency audit that doesn't completely fit this mold

I think we can refactor the shared pieces between that audit and these to a helper, but there's so much shared between generating the audit results here it felt like a waste to do anything less.

For smokehouse, it would be a shame to lose it for testing these audits. We probably do want to add some assets big enough to hit the thresholds, but replacing everything might be excessive.

Agreed, what about moving these to a new folder and start matching our smokehouse expectations files to our folder structure? That way there's less noise too. We'd only really introduce a minimum of ~100k total to exercise failure in each of these.

@patrickhulce
Copy link
Collaborator Author

patrickhulce commented Feb 13, 2017 via email

@@ -41,7 +40,7 @@ class UsesOptimizedImages extends Audit {
return {
category: 'Images',
name: 'uses-optimized-images',
description: 'Has optimized images',
description: 'Avoids unoptimized images',
Copy link
Contributor

Choose a reason for hiding this comment

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

Affirmative descriptions still feel better to me (where we can use them). How about aligning with PSI? They use a singular "Optimize images". WDYT about "Optimizes images" for us?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I switched them because I sympathized with the idea that telling users they did something when that thing doesn't apply to them doesn't make a lot of sense. I like the affirmative descriptions in isolation, but I do think consistency between audits within a category that's all about not doing something (shipping bytes) feels a lot smoother.

I definitely prefer "Optimizes images" to the double negative here, but could use guidance on the CSS affirmative, Uses most of its CSS is pretty lame

Copy link
Contributor

Choose a reason for hiding this comment

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

telling users they did something when that thing doesn't apply to them

Sort of why I think "Uses optimized images" is better than PSI's "Optimizes images".

The first says: "All the images LH found were optimized. Good job!"
The second says: "You're (actively) optimizing images" ...which as you say, may not be the case.

Copy link
Collaborator Author

@patrickhulce patrickhulce Feb 14, 2017

Choose a reason for hiding this comment

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

Any thoughts on CSS wording changes to also be affirmative? I'll give up soon if you don't have any ideas either I'll just live with the mismatch to push this through, haha :P

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea......hmm. We can stick with "avoids *" for now.

@@ -32,7 +29,7 @@ class UnusedCSSRules extends Audit {
return {
category: 'CSS',
name: 'unused-css-rules',
description: 'Uses 90% of its CSS rules',
description: 'Avoids unnecessary CSS',
Copy link
Contributor

Choose a reason for hiding this comment

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

"unnecessary CSS" might not be descriptive enough.
What do you think about Avoids including unnecessary CSS or Avoids loading unnecessary CSS to correlate with the theme of reducing bytes on page load?

preview: '',
url: 'URL',
totalKb: 'Original (KB)',
wastedKb: 'Savings (KB)',
Copy link
Contributor

Choose a reason for hiding this comment

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

just a thought: should we put total savings last...as a way to indicate it's representative of the webp/jpeg column that provides the most impact.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

+1 I like that idea, also makes the math clear ORIG x PERCENT = SAVINGS

@@ -39,7 +38,7 @@ class UsesResponsiveImages extends Audit {
return {
category: 'Images',
name: 'uses-responsive-images',
description: 'Has appropriately sized images',
description: 'Avoids oversized images',
Copy link
Contributor

Choose a reason for hiding this comment

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

"Uses appropriately sized images" or "Loads appropriately sized images"?

@patrickhulce
Copy link
Collaborator Author

updated smokehouse to have a new byte efficiency tester since there were no objections, tests should pass now PTAL :)

Copy link
Contributor

@ebidel ebidel left a comment

Choose a reason for hiding this comment

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

from me

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

A few smallish things

  1. kill "potential savings %" column and mostly merge it in to last column. So, the last column reads as "Potential Savings" and values are like 186 KB (60%).
  2. Since all the values in these tables include their own units, we don't need the headers to indicate units too. It also makes the headers longer, when we'd prefer to give that horizontal space to the URL.
  3. Title is a little awkward to read. image I'd go with "Avoids loading unnecessary CSS: Potential savings of 15KB (~70ms of page load)"

@patrickhulce
Copy link
Collaborator Author

with @paulirish's improvements:

image

@paulirish
Copy link
Member

love it.

@paulirish paulirish merged commit d1b9110 into master Feb 15, 2017
@paulirish paulirish deleted the dry_byte_efficiency branch February 15, 2017 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sort resources by potential savings, do not report negligible results
5 participants