Skip to content

perf(aio): improve unit test rebuild time - #16250

Merged
petebacondarwin merged 1 commit into
angular:masterfrom
IdeaBlade:aio-test-perf
Apr 24, 2017
Merged

petebacondarwin merged 1 commit into
angular:masterfrom
IdeaBlade:aio-test-perf

Conversation

@filipesilva

Copy link
Copy Markdown
Contributor

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (check one with "x")

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[x] Other... Please describe: performance improvement for aio unit tests

What is the current behavior? (You can also link to an open issue here)
Rebuild times for AIO unit test are somewhat slow currently: 15.809s (initial), 10.015s, 9.764s, 10.728s, 11.957s.

What is the new behavior?
This PR improves rebuild times: 16.551s (initial), 0.972s, 1.505s, 0.992s, 0.826s.

Does this PR introduce a breaking change? (check one with "x")

[ ] Yes
[x] No

If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...

Other information:

/cc @wardbell

Comment thread aio/src/test.ts Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Duplicate entry.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

True but harmless and has the virtue of making it easy to inspect if you have all of the @angular libraries you want when you inspect/extend this list.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm on the fence regarding this one. I defer to you.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't get it 😕 How does it help to have @angular/platform-browser-dynamic listed twice?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just to be clear, I am referring to the fact that there is the exact same import (import '@angular/platform-browser-dynamic';) a few lines below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh that's a mistake!

Comment thread aio/src/test.ts Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to import stuff that we don't use? Does it noticeably affect re-build time?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd rather have them all if it doesn't harm build times, just so I don't forget to add it later. Filipe's (internal) numbers show that the initial build time (the only build time that could be affected) is unchanged from the pre-PR figure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't need to, no. Will try to trim it down.

Comment thread aio/src/test.ts Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OOC, why does this help with rebuild times?

@wardbell wardbell Apr 21, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@gkalpak In a side conversation with the PR author he said

it bundles each spec separately so it should provide better performance by only rebuilding the specs that really need it.

And so it does.

The trick of gathering the spec files in a separate file (test-specs.ts) and then importing that here in test.ts seems weird but is essential magic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So what happens in webpack is that rebuilding chunks is fast in and of itself. But if anything changes on a given chunk, sourcemaps are rebuilt and that takes a long time.

This is why often builds stay on 92% optimizing assets and why turning off sourcemaps makes it faster.

What this tweak does is force webpack to make a separate, lazy chunk for all the spec files and dependencies. But we also list dependencies manually, so they don't get duplicated. This way, when sourcemaps are recalculated, it's super fast because it's not doing the vendor libs.

We do this another way in normal builds, but karma webpack does not support the other approach (using CommonsChunkPlugin, codymikol/karma-webpack#22).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But sourcemaps are already disabled in yarn test, so this shouldn't be the reason for slowness. Does this change mean that we could re-enable sourcemaps in yarn test with minimal overhead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I hadn't noticed they were turned off there. You're right, they can now be turned on with little to no overhead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Amended the PR to also remove the disabled sourcemaps.

@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 8dd4ff619b71de39fa42f372c8ec1cd6b2ee54cb is available here.

@wardbell wardbell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

EXCELLENT! Palpably improves dev/test cycle time.

I know you used an internal tool to measure those build times. Wish we could see them too.

Reader's note: this PR improves build time. It does not affect the time it takes for the tests themselves to run.

Approved with enthusiasm.

p.s. The currently failing e2e test is unrelated.

@wardbell wardbell added action: merge The PR is ready for merge by the caretaker comp: aio labels Apr 21, 2017
@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 55af12d8ff2c508a41623d5504f602d63e27ca6c is available here.

@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 6407ef6b72db6d04988c417ad60d31ec8cb2c0e2 is available here.

@intellix

Copy link
Copy Markdown

Also just tested this against an Angular CLI project with around ~400 tests and it's really helped the rebuilds. They're not getting stuck on 92% anymore for a couple of seconds for me

@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 6e5d7d1 is available here.

@gkalpak gkalpak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This speed-up is great 💯

@petebacondarwin

Copy link
Copy Markdown
Contributor

just checking that the e2e test failure was a flake before landing.

@petebacondarwin
petebacondarwin merged commit d7719aa into angular:master Apr 24, 2017
@filipesilva
filipesilva deleted the aio-test-perf branch April 25, 2017 13:29
@angular-automatic-lock-bot

Copy link
Copy Markdown

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 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants