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

Improve performance of HTML generator #186

Merged

Conversation

khanguy00
Copy link
Contributor

@khanguy00 khanguy00 commented Apr 30, 2020

getWebTreeMapData takes too much time with [combined] bundle. In my big project, with 10000 files (max directory depth: 11) in the combined bundle, it takes ~45s, while the rest of exploreResults only takes 3s in total.

This PR is about to move the combined bundle away from getWebTreeMapData(), and re-create it by merging the tree data of other bundles. The merging logic also costs ~2s in my project, but it's much less than 45s.

src/lib/html.ts Outdated
Comment on lines 25 to 35
// Get webtreemap data to update map on bundle select
let treeData = exploreResults.map<WebTreeData>((data) => ({
name: data.bundleName,
data: getWebTreeMapData(data.files),
}));

if (treeData.length > 1) {
treeData = [makeMergedTreeDataMap(cloneDeep(treeData))].concat(treeData);
}
const treeDataMap = { ...treeData };
const template = getFileContent(path.join(__dirname, 'tree-viz.ejs'));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Tranforms exploreResults to treeData
  • Adds the combined treeData ahead
  • Converts array of treeData to treeDataMap
  • Then allows to combine exploreResults (see code below)

src/lib/html.ts Outdated Show resolved Hide resolved
src/lib/html.ts Outdated
for (const result of treeData) {
const childTree = result.data;

childTree._name = result.name;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uses bundle name as the new name of child tree node.

@nikolay-borzov
Copy link
Collaborator

Update snapshots using test:update-snapshots script

@coveralls
Copy link

coveralls commented Apr 30, 2020

Coverage Status

Coverage decreased (-0.5%) to 97.394% when pulling e3d7e10 on khanguy00:improve-performance-html-generator into 7321483 on danvk:master.

khanguy00 and others added 5 commits May 2, 2020 09:17
- Call `addSizeToTitle` after merged webTreeData is created. As a rsult  `originalName` is not needed.
- Add a test for `makeMergedTreeDataMap`
src/lib/html.ts Outdated Show resolved Hide resolved
@nikolay-borzov nikolay-borzov added this to the 2.5.0 milestone May 6, 2020
@nikolay-borzov nikolay-borzov merged commit 1dbc03e into danvk:master May 6, 2020
@nikolay-borzov
Copy link
Collaborator

Thanks for your contribution!

@khanguy00 khanguy00 deleted the improve-performance-html-generator branch May 7, 2020 10:13
Comment on lines +57 to +63
bundles = [
{
name: COMBINED_BUNDLE_NAME,
size: formatBytes(exploreResults.reduce((total, result) => total + result.totalBytes, 0)),
},
...bundles,
];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh wait, I think it's better if we keep bundles as a const, so these line could be:

Suggested change
bundles = [
{
name: COMBINED_BUNDLE_NAME,
size: formatBytes(exploreResults.reduce((total, result) => total + result.totalBytes, 0)),
},
...bundles,
];
bundles.unshift({
name: COMBINED_BUNDLE_NAME,
size: formatBytes(exploreResults.reduce((total, result) => total + result.totalBytes, 0)),
});

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll apply this change in next commits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @nikolay-borzov , can you release this PR to npm? It's been a while since the last release, and I really want this to rollout my next release. (And don't forget to update the suggestion above). Many thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's weird. I don't remember why I decided not to release right when this PR was merged. I will take care of it this within this week

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.

I think you wanted to release this PR on 2.5.0 that you're working on it, right? That's why you added this to the milestone.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah. And for some reason, I thought #185 will be easy to do

@khanguy00 khanguy00 restored the improve-performance-html-generator branch May 7, 2020 10:20
@khanguy00 khanguy00 deleted the improve-performance-html-generator branch May 10, 2020 23:30
nikolay-borzov added a commit that referenced this pull request Aug 20, 2020
- Use `unshift` instead of spread operator
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.

3 participants