Skip to content

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

Merged
devtools-bot merged 30 commits into
masterfrom
treemap-data
Oct 6, 2020
Merged

new_audit: add script-treemap-data to experimental#11271
devtools-bot merged 30 commits into
masterfrom
treemap-data

Conversation

@connorjclark

@connorjclark connorjclark commented Aug 15, 2020

Copy link
Copy Markdown
Collaborator

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
Comment thread lighthouse-core/audits/treemap-data.js Outdated
Comment thread lighthouse-core/audits/treemap-data.js Outdated
/**
* @typedef Node
* @property {string} name
* @property {number} resourceBytes

Copy link
Copy Markdown
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
Copy Markdown
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 :)

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

Copy link
Copy Markdown
Contributor

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

Comment thread lighthouse-core/audits/treemap-data.js Outdated
Comment thread lighthouse-core/audits/treemap-data.js Outdated
Comment thread lighthouse-core/audits/treemap-data.js Outdated
Comment thread lighthouse-core/audits/treemap-data.js Outdated
Comment thread lighthouse-core/test/audits/treemap-data-test.js Outdated
expect(treemapData.scripts).toMatchSnapshot();
});

it('resource summary', () => {

@brendankenny brendankenny Sep 24, 2020

Copy link
Copy Markdown
Contributor

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

Comment thread lighthouse-core/test/test-utils.js Outdated

@brendankenny brendankenny left a comment

Copy link
Copy Markdown
Contributor

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

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

/** @type {Node} */

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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

Comment thread lighthouse-core/audits/script-treemap-data.js Outdated
Comment thread lighthouse-core/audits/script-treemap-data.js

@patrickhulce patrickhulce left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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