-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
new_audit: add script-treemap-data to experimental #11271
Conversation
/** | ||
* @typedef Node | ||
* @property {string} name | ||
* @property {number} resourceBytes |
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.
might be convinced to use transferBytes instead ..
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.
resource seems fine for the treemap visualization (though eventually we might want both?), we don't exactly want to minimize the size of these over there :)
const url = scriptElement.src; | ||
const bundle = bundles.find(bundle => url === bundle.script.src); | ||
const scriptCoverages = artifacts.JsUsage[url]; | ||
if (!bundle || !scriptCoverages) continue; |
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.
when does this happen? If it happens for decent-sized scripts, should they be included in some way still? (even if just an "other" category or whatever). If it's just for type checking or shouldn't really occur, add a comment?
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 was accidentally skipping all scripts without a source map. Messed that up during some refactoring.
expect(treemapData.scripts).toMatchSnapshot(); | ||
}); | ||
|
||
it('resource summary', () => { |
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.
Is it possible to move these to more specific tests? With a snapshot, when something changes all that's clear is that something has changed, and it may not be clear that it's a bad thing.
It also makes debugging start with a blank slate..instead of knowing that the failure is exactly that dependent modules aren't nested under their parents, or that names aren't trimmed of the sourceRoot, you have to start with, something has changed, track down what that is and what caused it, then go read the file under test to figure out if the original intention was that dependent modules should be nested under their parents or that names are trimmed of the sourceRoot (and also are there cases when those things shouldn't happen...).
There's probably some mixture of expect()
ing specific values and snapshots (with more specific test names :P) that would work best here.
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.
I've made a few more specific tests.
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.
some last style nits, but LGTM!
Over to @patrickhulce
const unusedJavascriptSummary = await UnusedJavaScriptSummary.request( | ||
{url: scriptElement.src, scriptCoverages, bundle}, context); | ||
|
||
/** @type {Node} */ |
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.
nit: don't need this, tsc's got your back :)
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 can change what line an error is reported on, and makes the error message less complex. You can see the difference by commenting out the name
property and seeing how the error changes.
// For every source file, apply the data to all components | ||
// of the source path, creating nodes as necessary. | ||
for (const [source, data] of Object.entries(sourcesData)) { | ||
addAllNodesInSourcePath(source || `<unmapped>`, data); |
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.
is the <unmapped>
fallback possible? It seems like things would be pretty broken if the source name was the empty string
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.
ah, nope. not possible.
There is an entry in sourcesWastedBytes
for (unmapped)
(see
const key = mapping.sourceURL || '(unmapped)'; |
lighthouse/lighthouse-core/test/audits/byte-efficiency/unused-javascript-test.js
Line 123 in 7008e55
"source": "(unmapped)", |
will add an item in parent issue to add a node for unmapped bytes.
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.
much easier for me to follow now thanks for the comments :)
I assume we might end up needing to tweak as the treemap viewer app evolves but this looks great to land 🎉
lighthouse-core/test/audits/__snapshots__/script-treemap-data-test.js.snap
Show resolved
Hide resolved
'b.js': {resourceBytes: 100, duplicatedNormalizedModuleName: 'blah'}, | ||
'c.js': {resourceBytes: 100, unusedBytes: 50}, | ||
}); | ||
expect(rootNode).toMatchObject( |
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.
thank youuuuuu :)
Thanks Brendan and Patrick! |
part of #11254
Example of
TreemapData
: https://gist.github.com/connorjclark/2c30fc7be0e6cbfd205a4a78964226dfSize in LHR, after removing fullpage screenshots from experimental: