Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

refactor: changed __UglifyJsPlugin dereference to use WeakSet instead #57

Merged
merged 1 commit into from
Jun 29, 2017

Conversation

hulkish
Copy link
Contributor

@hulkish hulkish commented Jun 29, 2017

So, as a proof of concept... I created this: https://github.com/hulkish/dummy

Pull that repo, then run:

yarn
node scripts/profile.js

You will see an output which looks like:

untouched_node@v6.11.0 compile...
untouched_node@v6.11.0 files length 68
untouched_node@v6.11.0 profiler.startProfiling()
untouched_node@v6.11.0: 27549.784ms
untouched_node@v6.11.0 profiler.stopProfiling()
untouched_node@v6.11.0 profile.export()
untouched_node@v6.11.0 profile saved: /Users/shargrove/dev/repos/dummy/untouched_node@v6.11.0.uglifyjs-webpack-plugin.cpuprofile
forEach_WeakSet_node@v6.11.0 compile...
forEach_WeakSet_node@v6.11.0 files length 68
forEach_WeakSet_node@v6.11.0 profiler.startProfiling()
forEach_WeakSet_node@v6.11.0: 14367.834ms
forEach_WeakSet_node@v6.11.0 profiler.stopProfiling()
forEach_WeakSet_node@v6.11.0 profile.export()
forEach_WeakSet_node@v6.11.0 profile saved: /Users/shargrove/dev/repos/dummy/forEach_WeakSet_node@v6.11.0.uglifyjs-webpack-plugin.cpuprofile

then, you can compare the output of these 2 folders:

  • dist/untouched_node@v6.11.0
  • dist/forEach_WeakSet_node@v6.11.0

The output is the same, but look at the significant difference in time.

@hulkish hulkish changed the base branch from master to feature-defaults June 29, 2017 03:15
@michael-ciniawsky michael-ciniawsky changed the title refactor: changed __UglifyJsPlugin dereference to use WeakSet instead refactor: changed __UglifyJsPlugin dereference to use WeakSet instead Jun 29, 2017
@michael-ciniawsky michael-ciniawsky added this to the 1.0.0 milestone Jun 29, 2017
@michael-ciniawsky
Copy link
Member

Change the base branch back to master please, since it seem to landed there yet :)

@hulkish hulkish changed the base branch from feature-defaults to master June 29, 2017 03:44
@michael-ciniawsky michael-ciniawsky self-assigned this Jun 29, 2017
@Jessidhia
Copy link

Jessidhia commented Jun 29, 2017

Interesting, I didn't expect using a WeakSet to actually improve performance by much; it just "felt right" considering how the extra key was added and used. But I guess the cost of forcing a hidden class change by adding an extra key was high enough.

It looks like this needs a rebase to get rid of the indent changes, though.

@mikesherov
Copy link

mikesherov commented Jun 29, 2017

@Kovensky that is to say, this was the old code:

asset = compilation.assets[file]
if(asset.__UglifyJsPlugin) {
	compilation.assets[file] = asset.__UglifyJsPlugin;
	return;
}
outputSource = uglify();
compilation.assets[file] = outputSource;
asset.__UglifyJsPlugin = outputSource;

So there's a dangling reference there. No object inside compilation.assets ever gets the prop appended! e.g. https://jsfiddle.net/jqs4c96k/2/

@mikesherov
Copy link

Oh interesting, the weakSet is in the wrong spot? Can different compilations have the same asset?

@hulkish
Copy link
Contributor Author

hulkish commented Jun 29, 2017

@mikesherov what u mean wrong spot?

@mikesherov
Copy link

Can be placed at RequestShortener's scope?

@hulkish
Copy link
Contributor Author

hulkish commented Jun 29, 2017

You're right... I considered that but i wonder if in principle it's actually better to keep it in 'optimize-chunk-assets` handler scope... For ex... i thought about how this might behave in watch mode and wondered if this would cause an issue.

@mikesherov
Copy link

It can't possibly, it's a WeakSet! It won't leak memory, and a match will only happen when it truly should happen!

@hulkish
Copy link
Contributor Author

hulkish commented Jun 29, 2017

Ah, very good point.

@michael-ciniawsky michael-ciniawsky merged commit 58e6900 into webpack-contrib:master Jun 29, 2017
@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Jun 29, 2017

Sry for the heads up, but could we triage landing/not landing uglify-es (#55) first before optimizing further 🙃 ?

@mikesherov
Copy link

YESSSSS

@michael-ciniawsky
Copy link
Member

ALRIGHTTTT 😛 :D

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

Successfully merging this pull request may close these issues.

4 participants