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 production build times #9295

Merged
merged 2 commits into from
Jan 23, 2018
Merged

Conversation

filipesilva
Copy link
Contributor

This PR adds cache support for UglifyJS and Build Optimizer, and executes Build Optimizer in parallel.

Benchmarks for ng build --prod:

@Toxicable
Copy link

@filipesilva
Looking at https://github.com/amireh/happypack#threads-number
Could you try bench-marking it with threads set to 4?

@Toxicable
Copy link

Also since we're adding a cache could we see some RAM benchmarks?

@clydin
Copy link
Member

clydin commented Jan 19, 2018

Using the number of cpu cores would probably be a good idea. Too many threads will end up hurting performance due to excessive context switching and too little will limit the potential performance improvement.

@Toxicable
Copy link

Since according to the readme there's diminishing returns after 4, I think something like this would be best

const cpus = require('os').cpus().length;
const happyCores = cpus > 4 ? 4 : cpus;

@clydin
Copy link
Member

clydin commented Jan 20, 2018

Most likely because the tests were run on a quad core system which would make 4 the best number to use. Especially since the readme says performance started to really suffer after 8.

@Toxicable
Copy link

@clydin Possibly, I think it would be worth doing our own analysis either way since this could be a big factor on the final speed

@filipesilva
Copy link
Contributor Author

I tried adding the CPU config to the same that uglifyjs-webpack-plugin uses, which in my case will be 7:

    extraPlugins.push(new HappyPack({
      verbose: false,
      threads: require('os').cpus().length - 1,

Then I ran cleared node_modules and ran 2 prod builds in a row:

  • default number of threads
    • no cache: 548029 ms (~9.1 minutes)
    • with cache: 479455 ms (~7.9 minutes)
  • 7 threads
    • no cache: 559157 ms (~9.3 minutes)
    • with cache: 454367 ms (~7.5 minutes)

I also tried a new project:

  • default number of threads
    • no cache: 15617 ms (~16 seconds)
    • with cache: 6350 ms (~6 seconds)
  • 7 threads
    • no cache: 16393 ms (~16 seconds)
    • with cache: 7527 ms (~8 seconds)

Doesn't seem a big difference overall. But I think making it variable it might be worth it for some environments with less than 3 CPUs to avoid spawning more threads than needed, but probably defaulting to 1 if there's just one CPU.

PR is amended accordingly.

@filipesilva filipesilva force-pushed the prod-cache-parallel branch 2 times, most recently from 117409a to 12ec358 Compare January 23, 2018 16:09
@filipesilva
Copy link
Contributor Author

I removed the parallelization to reduce risk since it looks like cache is what provided the bigger benefit.

@hansl hansl merged commit e654fb2 into angular:master Jan 23, 2018
@filipesilva filipesilva deleted the prod-cache-parallel branch January 25, 2018 10:34
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants