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

feat: add unused javascript audit #3085

Merged
merged 8 commits into from Aug 30, 2017
Merged

feat: add unused javascript audit #3085

merged 8 commits into from Aug 30, 2017

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Aug 23, 2017

fixes #1852
addresses comment from #1449 (comment)

  • Adds an unused-javascript audit to the full-config
  • Refactors the totalTransferred calculation from unused-css-rules into an estimateTransferSize method.
  • Changes the intermediate page from about:blank to a data URI with a blank page. Ran into another issue (http://crbug.com/757998) where navigating to about:blank is not sufficient to clear the previous page but a data URI is.
    This has led to a inexplicable breaking of screenshots in the trace which I'll need to investigate, but at least the bulk of this can be reviewed. This doesn't seem to be failing on Travis?

image

cc: @addyosmani


const ByteEfficiencyAudit = require('./byte-efficiency-audit');

const IGNORE_THRESHOLD_IN_BYTES = 2048;
Copy link
Contributor

Choose a reason for hiding this comment

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

where does this val come from? Can you add a comment if there's research?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no research it's just in line with the rest of the byte efficiency audits to not be too noisy about small things that have minimal savings (others are also 2kb or 4kb)

@patrickhulce
Copy link
Collaborator Author

* @param {!WebInspector.NetworkRequest} networkRecord
* @param {number} totalBytes
* @param {string=} resourceType
* @param {number=} compressionRatio
Copy link
Member

Choose a reason for hiding this comment

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

any point to compressionRatio as a parameter if no caller uses it?

Copy link
Member

Choose a reason for hiding this comment

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

could also do a local lookup chart based on resourceType (if we're going to do anything but 0.5)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

making it controllable via the tests was a good sanity check, but I can remove if you think it's more trouble than its worth

@@ -58,6 +58,30 @@ class UnusedBytes extends Audit {
}

/**
* @param {!WebInspector.NetworkRequest} networkRecord
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 jsdoc description? It's not immediately obvious what totalBytes is here and what's being estimated from 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.

done

@@ -10,6 +10,9 @@ const Audit = require('../audits/audit');
const URL = require('../lib/url-shim');
const NetworkRecorder = require('../lib/network-recorder.js');

// Base64 encoded blank page <html></html>
const BLANK_URL = 'data:text/html;base64,PGh0bWw+PC9odG1sPg==';
Copy link
Member

Choose a reason for hiding this comment

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

we definitely need to look at any other implications of switching to this, but it's encouraging that the smoke tests are ok with it

@@ -0,0 +1,64 @@
/* eslint-disable */
Copy link
Member

Choose a reason for hiding this comment

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

license

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,133 @@
/**
* @license
Copy link
Member

Choose a reason for hiding this comment

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

short license?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


/**
* @param {!Artifacts} artifacts
* @return {{results: !Array<!Object>, tableHeadings: !Object}}
Copy link
Member

Choose a reason for hiding this comment

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

  • can results be made more specific? It would be nice to have a byte efficiency audit result type around somewhere.
  • tableHeadings should be headings and is an array of some details type

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. will do
  2. done

.then(_ => options.driver.sendCommand('Profiler.startPreciseCoverage'));
}

afterPass(options) {
Copy link
Member

Choose a reason for hiding this comment

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

return type for artifact would be 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

}

/**
* @param {{functions: !Array<{ranges: {startOffset: number, endOffset: number}}>}} script
Copy link
Member

Choose a reason for hiding this comment

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

also count: number

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

}

/**
* @param {{unusedLength: number, contentLength: number}} wasteData
Copy link
Member

Choose a reason for hiding this comment

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

array

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

for (const range of func.ranges) {
if (range.count === 0) {
for (let i = range.startOffset; i < range.endOffset; i++) {
unusedByIndex[i] = 1;
Copy link
Member

Choose a reason for hiding this comment

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

this seems really inefficient, but it's nice that it's so straightforward :) I guess we're only talking about 10s of MB even when uncompressed, so should be ok-ish until/if we hit some performance issues with it (or we want more out of coverage information)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

discussed in person, but it's actually much more efficient since flattening the many duplicated used ranges alone usually takes more time than iterating through the unused ranges (since there's only one range reporting the unused range)

@brendankenny
Copy link
Member

brendankenny commented Aug 28, 2017

not seeing any screenshot issues on my machine, either 👍

@addyosmani
Copy link
Member

Great work. Overall, this looks like it's headed in the right direction. It would be great if we could link to a doc or include a note with the caveat around "potential savings" via coverage (e.g check to see the impact immediate interactions may have on these numbers, take a closer look at the coverage panel for more insights etc).

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.

looking good (while we figure out the about:blank thing)

@@ -58,6 +58,9 @@ class UnusedBytes extends Audit {
}

/**
* Estimates the number of bytes this network record consumed on the network based on the
* uncompressed size, uses the actual transfer size from the network record if applicable.
Copy link
Member

Choose a reason for hiding this comment

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

maybe something like Estimates the number of bytes this network record would have consumed on the network based on the uncompressed size totalBytes, ...? What totalBytes is is probably the thing that needs the most explanation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

module.exports = JsUsage;

/** @typedef {{functions: !Array<{ranges: {count: number, startOffset: number, endOffset: number}}>}} */
JsUsage.JsUsageArtifact; // eslint-disable-line no-unused-expressions
Copy link
Member

Choose a reason for hiding this comment

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

this could also live in the Artifacts.js typedefs, but it's also nice here, local to where it's created, until/if we ever need a lot of references to it (and other artifacts) elsewhere.

@patrickhulce
Copy link
Collaborator Author

I reverted the about:blank change for now since the impact is unknown and risky. The original bug that needed the workaround has been fixed in Canary anyway, so we're not any worse off than we were before.

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!

@patrickhulce patrickhulce merged commit 5bf4a0f into master Aug 30, 2017
@patrickhulce patrickhulce deleted the js_coverage branch August 30, 2017 16:07
thisizkp pushed a commit to thisizkp/lighthouse that referenced this pull request Sep 2, 2017
* feat: add unused javascript audit

* update smokehouse to support stable

* feedback

* scratch

* consistent return typedef

* revert about:blank changes

* update estimateTransferSize comment

* update for stable issue
@martinschierle
Copy link

I can't seem to get the 'unused-javascript' audit anymore in newer Lighthouse versions - but also can't see any hint that (or why) it was removed - is this still available, and if yes, why not?

@patrickhulce
Copy link
Collaborator Author

@martinschierle it's only in the "full config" right now. You can only get it currently by running lighthouse --preset=full <url>

@martinschierle
Copy link

Thanks for the quick response - great to know, I wasn't even aware that there is a 'full' option, thanks! ;-)

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.

Audit: Add JS coverage audit
5 participants