nolanlawson / optimize-js

Optimize a JS file for faster parsing (UNMAINTAINED)

Home Page:https://nolanlawson.github.io/optimize-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not as optimized for Webpack as it could be

nolanlawson opened this issue · comments

Looking at the Webpack output, it appears to me that those modules that are passed in as an array to another function (and are therefore not wrapped) should probably be wrapped. As with Browserify, I'd wager it's rare for a module not to be immediately require()d, meaning that wrapping all of them would provide a perf boost.

Need a reasonably-sized Webpack bundle in order to test this and confirm, though. TODO: find some large-ish library that is built with Webpack.

Did we test these w/ the V8LazyParseWebpackPlugin?

@TheLarkInn if I had some guidance on moving to Webpack 2, I would try it out.

That plugin may work with webpack 1 also, but what specifically do you need help with for webpack 2.

This may be a good first patch, given that you basically just need to add a new test case (input.js and output.js) and then add a new condition to check if the function is inside an array inside of a call expression. ASTExplorer is very helpful here.

@TheLarkInn Does lazyparseplugin adds the parans for the modules in array?

It sure does!! If you have a large app feel free to try it. Only catch is that I believe you have to tell UglifyJsPlugin compress option to set negate_iife: false.

@vigneshshanmugam if you have an app that we can test with I'd be interested to see the statistics.

@TheLarkInn I tried it and updated the gist. It fails to wrap the inner functions as well.

Also updated the readme here - TheLarkInn/LazyParseWebpackPlugin#4

Awesome!!! I intentionally didn't wrap the inner functions inside modules because I wasn't sure the benefit, but it's definitely possible to use a webpack parser plugin to do this.

Ahh got it.. But i believe the benchmarks in the README includes the wrapping for inner functions as well.. Anyways as you said, its possible to do this :)

Fixed in #33