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
Conversation
|
||
const ByteEfficiencyAudit = require('./byte-efficiency-audit'); | ||
|
||
const IGNORE_THRESHOLD_IN_BYTES = 2048; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
⛰ |
* @param {!WebInspector.NetworkRequest} networkRecord | ||
* @param {number} totalBytes | ||
* @param {string=} resourceType | ||
* @param {number=} compressionRatio |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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=='; |
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
license
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
short license?
There was a problem hiding this comment.
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}} |
There was a problem hiding this comment.
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 beheadings
and is an array of some details type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- will do
- done
.then(_ => options.driver.sendCommand('Profiler.startPreciseCoverage')); | ||
} | ||
|
||
afterPass(options) { |
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also count: number
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)
not seeing any screenshot issues on my machine, either 👍 |
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). |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 📜 🔢 ⬇️
LGTM!
* 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
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? |
@martinschierle it's only in the "full config" right now. You can only get it currently by running |
Thanks for the quick response - great to know, I wasn't even aware that there is a 'full' option, thanks! ;-) |
fixes #1852
addresses comment from #1449 (comment)
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?cc: @addyosmani