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

Upgrade webpack to 2.x #14786

Merged
merged 10 commits into from
Jun 27, 2017
Merged

Upgrade webpack to 2.x #14786

merged 10 commits into from
Jun 27, 2017

Conversation

samouri
Copy link
Contributor

@samouri samouri commented Jun 6, 2017

Heavily building off of the work done by @ehg in #10799, I'm attempting to upgrade our build system to Webpack 2.x. One of the largest draws is the promise of tree shaking which can reduce the size of our bundles.

Problems to fix:

@samouri samouri added Build [Type] Performance [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it labels Jun 6, 2017
@samouri samouri self-assigned this Jun 6, 2017
@matticbot
Copy link
Contributor

@matticbot matticbot added the [Size] L Large sized issue label Jun 6, 2017
@samouri
Copy link
Contributor Author

samouri commented Jun 6, 2017

It looks like there is now a webpack-provided way of creating the kind of long-term caching we were striving for with WebpackStableBuildPlugin. I'll follow the instructions here

@matticbot matticbot added [Size] XL Probably needs to be broken down into multiple smaller issues and removed [Size] L Large sized issue labels Jun 6, 2017
@ehg
Copy link
Member

ehg commented Jun 6, 2017

cc @jsnmoon for codemod goodness.

Also, we should just get rid of react-hot for the moment.

@@ -163,7 +163,7 @@ function singleEnsure( chunkName ) {
module.exports = function( content ) {
var sections;

this.cacheable && this.cacheable();
// this.cacheable && this.cacheable(); // TODO @ehg why did you comment this out?
Copy link
Member

Choose a reason for hiding this comment

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

No longer needed in webpack2. On by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

awesomesauce

@@ -48,6 +48,7 @@ const HEADER_OFFSET_TOP = 46;
const MIN_DISTANCE_BETWEEN_RECS = 4; // page size is 7, so one in the middle of every page and one on page boundries, sometimes
const MAX_DISTANCE_BETWEEN_RECS = 30;


Copy link
Member

Choose a reason for hiding this comment

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

:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops!

@samouri
Copy link
Contributor Author

samouri commented Jun 7, 2017

@ehg why do we want codemods in this pr? Ideally we can keep this to just upgrading to webpack2 and trying to maintain the same feature set

@ehg
Copy link
Member

ehg commented Jun 7, 2017

@ehg why do we want codemods in this pr? Ideally we can keep this to just upgrading to webpack2 and trying to maintain the same feature set

We don't. I'm just looping Jason in :)

@ehg
Copy link
Member

ehg commented Jun 7, 2017

Also, I should explain myself a bit better here:

Also, we should just get rid of react-hot for the moment.

I've noticed quite a few problems involving tree-shaking and react-hot, so we might as well just remove it all together, then come back to it when/if we want it. It's pretty useless considering out iterative build times atm IMHO :)

@samouri samouri force-pushed the update/webpack2-2 branch from 8801509 to e1ace8f Compare June 8, 2017 09:44
@samouri
Copy link
Contributor Author

samouri commented Jun 8, 2017

HMR is now working in this branch! 🎉
hmr

What problems were you seeing @ehg

@samouri
Copy link
Contributor Author

samouri commented Jun 8, 2017

Build Perf analysis:

webpack 1.3.x build times:

  • first build: server: 32s, css: 20s, client: 153s
  • second build: server: 32s, css: 0s, client: 42s // question: is babel-cache the only thing making this faster?
  • incremental build: 25s

webpack 2.6.1 build times:

  • first build: server: 48s, css: 19s, client: 299s
  • second build: server: 48s, css: 0s, client: 178s
  • incremental build: 17s

webpack 2.3.2 build times: Airbnb employee says that 2.3.2 is faster.
note: may be an unfair comparison -- needed to remove NamedChunksPlugin.

  • second build: server: 42s, client: 92s
  • incremental build: 16s

All tests conducted on a 2015 Macbook Pro


Conclusions:
incremental builds have gotten better, but initial build is much worse

@samouri
Copy link
Contributor Author

samouri commented Jun 9, 2017

I've created a stats.json file with webpack 2.6.1 for use with the webpack build analysis tool located at: http://webpack.github.io/analyse/ .

TODO: drop link to file

I'm currently having some trouble figuring out what it all means, but there are some suggestions re. module name resolution etc that seem like they could speed up the builds. In particular this affects notifications-client

@ehg
Copy link
Member

ehg commented Jun 9, 2017

What problems were you seeing @ehg

It wasn't so much that HMR/react-hot weren't working on my initial branch. Once I enabled tree-shaking, I got into some trouble. This was because of import hoisting with react-hot v1, but I've seen problems mentioned with v3 too.

@samouri
Copy link
Contributor Author

samouri commented Jun 12, 2017

I'm not too happy about the DevEx performance hit that a straight migration to the latest webpack causes.

I'm spinning a PR off of this one to try to speed things upcreating a dev-only DLL chunk. We used to do this but stopped because we ran into issues re. caching: #11867

By only doing this in dev, it shouldn't affect caching in prod

@samouri
Copy link
Contributor Author

samouri commented Jun 12, 2017

It wasn't so much that HMR/react-hot weren't working on my initial branch. Once I enabled tree-shaking, I got into some trouble

For now i'll keep it in. If we need to strip it out in a future pr then so be it :(

@DanReyLop
Copy link
Contributor

I'm not too happy about the DevEx performance hit that a straight migration to the latest webpack causes.

What about we migrate to 2.3.2 for now? The performance regression was in 2.4.0. Hopefully in a few weeks we can jump directly to 3.X when that issue is solved.

@samouri
Copy link
Contributor Author

samouri commented Jun 13, 2017

What about we migrate to 2.3.2 for now? The performance regression was in 2.4.0. Hopefully in a few weeks we can jump directly to 3.X when that issue is solved.

Is there any reason to think 3.X will solve the perf issue?

2.3.2 is missing the two plugins essential for caching

@DanReyLop
Copy link
Contributor

Is there any reason to think 3.X will solve the perf issue?

webpack/webpack#4863 is marked as Urgent priority. It's not fixed yet, but there's reason to believe they will try to fix it soon.

2.3.2 is missing the two plugins essential for caching

Oh, damn. I guess you could try forking webpack and reverting webpack/webpack@983904c (which is the cause of the performance regression), but that seems a bit extreme.

@samouri
Copy link
Contributor Author

samouri commented Jun 13, 2017

Oh, damn. I guess you could try forking webpack and reverting webpack/webpack@983904c (which is the cause of the performance regression), but that seems a bit extreme.

We could also bundle calypso with the source for the two plugins in question and then delete the files when we upgrade:

  1. https://github.com/webpack/webpack/blob/master/lib/NamedChunksPlugin.js
  2. https://github.com/webpack/webpack/blob/master/lib/NamedModulesPlugin.js

@samouri
Copy link
Contributor Author

samouri commented Jun 13, 2017

By using the cache options for babel-loader, the commit bcb59d4 Speeds up bundler build from 42s --> 13s 🎉

Copy link
Contributor

@DanReyLop DanReyLop left a comment

Choose a reason for hiding this comment

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

It works fine now on Windows. If that was the only blocker, you can 🚢 it :)

@matticbot
Copy link
Contributor

@samouri This PR needs a rebase

@samouri
Copy link
Contributor Author

samouri commented Jun 27, 2017

Up until now I had only been testing local build times. I'm going to merge this in the next few hours so I just tested the docker build times as well.

when running the command: time npm run build-docker

before: 9.07s user 1.95s system 2% cpu 6:41.59 total
after: 9.14s user 2.03s system 3% cpu 5:00.50 total

Thats a reduction from 6:41 --> 5:00 🎉

@blowery
Copy link
Contributor

blowery commented Jun 27, 2017

when running the command: time npm run build-docker

I wonder if we want to tweak https://github.com/amireh/happypack#threads-number at all. How many cores do our docker build instances get...?

@samouri
Copy link
Contributor Author

samouri commented Jun 27, 2017

@blowery: definitely something we can and should tweak! We'll want to do some testing directly on the machines doing our docker builds.

@samouri samouri merged commit 46d5676 into master Jun 27, 2017
@samouri samouri deleted the update/webpack2-2 branch June 27, 2017 16:37
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jun 27, 2017
samouri added a commit that referenced this pull request Jun 28, 2017
samouri added a commit that referenced this pull request Jun 28, 2017
samouri added a commit that referenced this pull request Jun 28, 2017
samouri added a commit that referenced this pull request Jul 3, 2017
samouri added a commit that referenced this pull request Jul 10, 2017
samouri added a commit that referenced this pull request Jul 10, 2017
* Revert "Revert "Upgrade webpack to 2.x (#14786)" (#15617)"

This reverts commit f1cffef.

* Add in NameAllModulePlugins + update shrinkwrap

* upgrade to 3.0 and name all modules/chunks

* vendor chunks minChunks infinity so it only includes what we specify

* Update shrinwrap + add peer dependency

* cross-env for webpack-dashboard

* remove copied NamedModulesPlugin

* remove ChunkFileNamePlugin

* fix error handling + modify readme.md

* remove ajv, bump webpack3, update shrinkwrap

* add ajv back in

* delete cruft empty concat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build Framework [Size] XL Probably needs to be broken down into multiple smaller issues [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Type] Performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants