-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Watch mode ~2 times slower than regular test run. #7341
Comments
@SimenB @rogeliog @rubennorte any ideas what's causing this? Checked just now again and it also affects our master branch. |
Totally missed this.
Agreed, not sure why it's not
We can mention it's
Yeah, totally. Or at least minimal overhead. The slowness seems worse than a single less core would indicate, doesn't it? We'll be focusing on profiling jest at the summit, hopefully we can also make some perf improvements, or at least understand why things perform the way they do |
I'm looking into this. Will resolve. |
## Summary Resolves #7341 This PR dramatically improves watch mode performance, bringing it in line with single run mode performance. It accomplishes that by: - Workers previously initialized a new `ModuleMap` and `Resolver` for every test in watch mode. Now, those objects are only initialized once when the worker is setup. - In the main thread, caching the conversion of `ModuleMap` to a JSON-friendly object. - Allowing watch mode to use the same number of CPUs as single run mode. ## Benchmarks I benchmarked against Jest's own test suite, excluding e2e tests which don't provide good signal because they individually take a long time (so startup time for the test is marginalized). The numbers show that running in Watch mode previously added an extra 35%~ of runtime to the tests but that has now been reduced to almost nothing. Watch mode should now just be paying a one-time initial cost for each worker when the haste map changes instead of paying that same cost for _every_ test run. ### branch: master `yarn jest ./packages` Run time: 15.091s `yarn jest ./packages --watch` Run time: 23.234s ### branch: watch-performance `yarn jest ./packages` Run time: 14.973s `yarn jest ./packages --watch` Run time: 15.196s ## Test plan - All tests pass. - Benchmarked to verify the performance wins. - Verified that when the haste map is updated, the update is propagated out to all workers.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
Running all tests while in watch mode is ~twice as slow as running all tests outside of watch mode.
This is with the same forced number of workers. The CLI docs state that the default is the number of cores the host machine has, however, in my case I’m noticing that it will actually run by default with
N-1
workers, presumably to allow for the parent process and some headroom for other processes (?). Additionally, when running in watch mode it will run by default withN-2
workers; which is less clear to me why that isn’t alsoN-1
, as naively I’d think the master process has to do roughly the same amount of work as when not running in watch mode.There are other reports elsewhere related to running tests in watch mode:
However, trying out older versions did not yield any results for me. I tried back as far as
21.2.1
.Jest 21.2.1
Note that these seem to take shorter than the other version tests, but that’s only because of (snapshot) test failures. Between the watch and normal test runs the difference is still ~2x.
Jest 22.4.4
Jest 23.0.0
Jest 23.1.0
Jest 23.2.0
Jest 23.6.0
To Reproduce
Steps to reproduce the behavior:
Then make sure to run tests with and without watch mode using the same number of workers.
Expected behavior
--maxWorkers
to reflect the actual defaults.Link to repl or repo (highly encouraged)
Not a minimal repo, but a real one that shows real numbers https://github.com/artsy/reaction
Run
npx envinfo --preset jest
The text was updated successfully, but these errors were encountered: