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

new_audit: add script-treemap-data to experimental #11271

Merged
merged 30 commits into from
Oct 6, 2020
Merged

Conversation

connorjclark
Copy link
Collaborator

@connorjclark connorjclark commented Aug 15, 2020

part of #11254

Example of TreemapData: https://gist.github.com/connorjclark/2c30fc7be0e6cbfd205a4a78964226df

Size in LHR, after removing fullpage screenshots from experimental:

coursehero.com, 105 KB aka 22% of .audits
cnn.com, 48 KB aka 6% of .audits

@connorjclark connorjclark requested a review from a team as a code owner August 15, 2020 03:15
@connorjclark connorjclark requested review from brendankenny and removed request for a team August 15, 2020 03:15
/**
* @typedef Node
* @property {string} name
* @property {number} resourceBytes
Copy link
Collaborator Author

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 ..

Copy link
Collaborator

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 :)

lighthouse-core/audits/treemap-data.js Outdated Show resolved Hide resolved
lighthouse-core/audits/treemap-data.js Outdated Show resolved Hide resolved
const url = scriptElement.src;
const bundle = bundles.find(bundle => url === bundle.script.src);
const scriptCoverages = artifacts.JsUsage[url];
if (!bundle || !scriptCoverages) continue;
Copy link
Member

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?

Copy link
Collaborator Author

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.

lighthouse-core/audits/treemap-data.js Outdated Show resolved Hide resolved
lighthouse-core/audits/treemap-data.js Outdated Show resolved Hide resolved
lighthouse-core/audits/treemap-data.js Outdated Show resolved Hide resolved
lighthouse-core/audits/treemap-data.js Outdated Show resolved Hide resolved
lighthouse-core/test/audits/treemap-data-test.js Outdated Show resolved Hide resolved
expect(treemapData.scripts).toMatchSnapshot();
});

it('resource summary', () => {
Copy link
Member

@brendankenny brendankenny Sep 24, 2020

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.

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've made a few more specific tests.

lighthouse-core/test/test-utils.js Outdated Show resolved Hide resolved
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.

some last style nits, but LGTM!

Over to @patrickhulce

lighthouse-core/test/audits/script-treemap-data-test.js Outdated Show resolved Hide resolved
lighthouse-core/audits/script-treemap-data.js Outdated Show resolved Hide resolved
const unusedJavascriptSummary = await UnusedJavaScriptSummary.request(
{url: scriptElement.src, scriptCoverages, bundle}, context);

/** @type {Node} */
Copy link
Member

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 :)

Copy link
Collaborator Author

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);
Copy link
Member

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

Copy link
Collaborator Author

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)';
/ ), but atm this audit doesn't surface unmapped bytes. The source datas are made by iterating the bundle files, which will always have a non empty string.

will add an item in parent issue to add a node for unmapped bytes.

lighthouse-core/audits/script-treemap-data.js Outdated Show resolved Hide resolved
lighthouse-core/audits/script-treemap-data.js Show resolved Hide resolved
Copy link
Collaborator

@patrickhulce patrickhulce left a 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 🎉

'b.js': {resourceBytes: 100, duplicatedNormalizedModuleName: 'blah'},
'c.js': {resourceBytes: 100, unusedBytes: 50},
});
expect(rootNode).toMatchObject(
Copy link
Collaborator

Choose a reason for hiding this comment

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

thank youuuuuu :)

@connorjclark
Copy link
Collaborator Author

Thanks Brendan and Patrick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants