jest: Jest 24 is 67% slower than Jest 23.6.0 on the same test suite
š Bug Report
Thanks for your hard work releasing jest 24!
A clear and concise description of what the bug is.
On jest 23.6.0 my test collection that totals 49 test suites and 700 tests took on average 11.9 seconds to run. Now in jest 24.0.0 it takes 19.9 seconds to run, with no changes of any kind to my code, tests or environment other than upgrading to jest 24. Iām not doing anything fancy.
This is a serious performance regression. I want to use jest 24 to take advantage of test.todo
but I canāt afford to have my tests take 67% longer to run - thatās a real drop in my productivity.
Any suggestions how to diagnose this further or fix this issue? I canāt post source code because this is proprietary code Iām working on. How can we fix this performance regression?
To Reproduce
Steps to reproduce the behavior:
Run a set of tests in jest 23.6.0. Run that same set of tests in jest 24.0.0.
Expected behavior
A clear and concise description of what you expected to happen.
Jest 24.0.0 should NOT be 67% slower than jest 23.6.0 for the same set of tests.
Link to repl or repo (highly encouraged)
Please provide either a repl.it demo or a minimal repository on GitHub.
Issues without a reproduction link are likely to stall.
Run npx envinfo --preset jest
Paste the results here:
System:
OS: macOS High Sierra 10.13.6
CPU: (4) x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
Binaries:
Node: 10.15.0 - ~/.nvm/versions/node/v10.15.0/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.15.0/bin/npm
npmPackages:
jest: ^24.0.0 => 24.0.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 15
- Comments: 31 (13 by maintainers)
Just to say that Iām seeing the same as @CrOrc. Every run of jest with 24.0.0 produces a new
jest-transform-cache
folder plus newperf-cache
andhaste-map
. Hence every test run takes as long as the first - the cache seems to be ignored. This doesnāt happen with jest 23.6.0.@mucsi96 The issue with TS being slow may be caused by the order of module extension resolution. By default, Jest searches first for
['js', 'json', 'jsx', 'ts', 'tsx', 'node']
ā so TS is supported, but at a performance cost. You can adjust themoduleFileExtensions
config, to havets
andtsx
at the very beginning, e.g.['ts', 'tsx', 'js', 'json', 'jsx', 'node']
.However, looking at the source, CRA has its own list, which is not allowed to be overridden: https://github.com/facebook/create-react-app/blob/b96ac6c2c007db85812a6e9c0ec54509019c0fea/packages/react-scripts/config/paths.js#L49-L61. You could try passing it as a flag to the CLI, but not sure about that. Iād try adjusting the list in node_modules, making sure it works faster and then send a PR to CRA with adjusted
moduleFileExtensions
for TSI can confirm caching of transformed files are broken.
Itās due to this line (from #5862): https://github.com/facebook/jest/blob/31b81ba37eb779161b6db78aa862c0bcd6465bd5/packages/jest-config/src/normalize.js#L272
Removing it speeds up rerunning the same tests by 300% for me in watch mode.
When we get to the cache key, the entire config serialized as a string is part of the cache name, and that will change for every single invocation of Jest:
https://github.com/facebook/jest/blob/31b81ba37eb779161b6db78aa862c0bcd6465bd5/packages/jest-runtime/src/ScriptTransformer.js#L84
Also wondering where to set the
name
option - it is not documented on https://jestjs.io/docs/en/configuration.htmlSetting it in my
jest.config.js
did not fix the issue.PR: #7746
I have tried
['ts', 'tsx', 'js', 'json', 'jsx', 'node']
but it made the execution even slower. Probably due to single React component and test vs. much more build-in modules.@mucsi96 a big part of that is likely micromatch, which is already known as a performance problem and will be fixed in 25
Any chance of getting a 24.0.1 patch release to fix this? š As it stands we are unable to use 24.0.0 due to the significant perf drop ā¦ Thanks!
Setting
name
in myjest.config.js
file does significantly speed up runs after the first one, but even after that Iāve found Jest 24 is about 50% slower than Jest 23.Both of those times are from a warm start (I ran Jest twice before recording the time).
Unfortunately I canāt share the code. Itās running around 300 test suites, around 3000 tests, and around 300 snapshots.
Edit:
I also have
api.cache.using(() => process.env.NODE_ENV)
in mybabel.config.js
, doesnāt seem to help.Sorry, where do we set the name? I only have a single config and it is declared in
package.json
. Adding aname
property inside thejest
object didnāt help.workaround is to set
name
in your configTo me 24 seems slower when there is a cache available, but about the same as 23 when there is no cache, so it seems like @CrOrc is on to something. Here are my results (ran the tests three times with each config):
23.6.0 - Runs after clearing the cache with
--clearCache
:Test Suites: 36 passed, 36 total Tests: 553 passed, 553 total Snapshots: 48 passed, 48 total Time: 64.927s
Test Suites: 36 passed, 36 total Tests: 553 passed, 553 total Snapshots: 48 passed, 48 total Time: 54.173s
Test Suites: 36 passed, 36 total Tests: 553 passed, 553 total Snapshots: 48 passed, 48 total Time: 59.353s
23.6.0 - Runs without clearing the cache:
Test Suites: 36 passed, 36 total Tests: 553 passed, 553 total Snapshots: 48 passed, 48 total Time: 36.196s, estimated 60s
Test Suites: 36 passed, 36 total Tests: 553 passed, 553 total Snapshots: 48 passed, 48 total Time: 32.83s, estimated 33s
Test Suites: 36 passed, 36 total Tests: 553 passed, 553 total Snapshots: 48 passed, 48 total Time: 32.278s
24.0.0 - Runs after clearing the cache with
--clearCache
:Test Suites: 36 passed, 36 total Tests: 553 passed, 553 total Snapshots: 48 passed, 48 total Time: 56.718s
Test Suites: 36 passed, 36 total Tests: 553 passed, 553 total Snapshots: 48 passed, 48 total Time: 64.682s
Test Suites: 36 passed, 36 total Tests: 553 passed, 553 total Snapshots: 48 passed, 48 total Time: 61.646s
24.0.0 - Runs without clearing the cache:
Test Suites: 36 passed, 36 total Tests: 553 passed, 553 total Snapshots: 48 passed, 48 total Time: 42.998s
Test Suites: 36 passed, 36 total Tests: 553 passed, 553 total Snapshots: 48 passed, 48 total Time: 44.611s
Test Suites: 36 passed, 36 total Tests: 553 passed, 553 total Snapshots: 48 passed, 48 total Time: 48.576s
For me the Jest keeps writing new jest-transform-cache folder on every jest run.