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

perf(optimized-images): use Audits.getEncodedResponse #3087

Merged
merged 2 commits into from
Aug 24, 2017
Merged

Conversation

patrickhulce
Copy link
Collaborator

Uses the new Audits.getEncodedResponse method to determine the size savings. Time savings varies since the canvas method was more variable than outright slow but some runs went from ~6s to ~500ms. Also enables fast checking of cross-origin images which was previously impossible.

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.

this is great! Just a few clarifications, mostly in comments :)

@@ -88,24 +93,49 @@ class OptimizedImages extends Gatherer {

/**
* @param {!Object} driver
* @param {string} requestId
* @param {string} encoding
Copy link
Member

Choose a reason for hiding this comment

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

maybe a note that this will either be jpeg or webp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good call, done

};
});
}).catch(err => {
if (/wasn't found/.test(err.message)) {
Copy link
Member

Choose a reason for hiding this comment

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

re-throw error otherwise?

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 still seemed reasonable to try the fallback path while we have it if this failed, but I'd rather know about failures for now at least until we release so sgtm :)

}).catch(err => {
if (/wasn't found/.test(err.message)) {
// Mark non-support so we don't keep attempting the protocol method over and over
this._getEncodedResponseUnsupported = true;
Copy link
Member

Choose a reason for hiding this comment

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

can we include something like _getEncodedResponseUnsupported on the extendedInfo? Not the most elegant thing, but when looking at old reports (e.g. http archive) it would be good to have an easy way to know when the results include all images, including cross origin ones. Other ways of doing that would also be good (lighthouse version would work in a pinch, but nice to have something audit-local)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah sure seem good to track this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added a fromProtocol property to the image result

}).then(result => {
if (result) return result;

// Take the slower/same-origin-limited fallback path if getEncodedResponse isn't available yet
Copy link
Member

Choose a reason for hiding this comment

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

maybe an additional note that cross-origin images aren't supported so it's clear until we delete?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

split the comment to make it more explicit

@@ -22,49 +22,49 @@ const traceData = {
{
_url: 'http://google.com/image.jpg',
_mimeType: 'image/jpeg',
_resourceSize: 10,
_resourceSize: 10000,
Copy link
Member

Choose a reason for hiding this comment

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

what's the deal with this change? Just more realistic sizes/getting above the 4k cutoff?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah just needed to go above the minimum image size

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!
📐🖼 🐇

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.

2 participants