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)

Most upvoted comments

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 new perf-cache and haste-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 the moduleFileExtensions config, to have ts and tsx 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 TS

I 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.html

Setting it in my jest.config.js did not fix the issue.

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!

On Feb 4, 2019 at 3:01 PM, <Dylan Vann (mailto:notifications@github.com)> wrote:

Setting name in my jest.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.

Jest 23: 70s Jest 24: 105s

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.

ā€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub (https://github.com/facebook/jest/issues/7732#issuecomment-460448031), or mute the thread (https://github.com/notifications/unsubscribe-auth/AmWxt93AFetN_h5zaBoK1rQjV0g0VLAHks5vKLu4gaJpZM4aVLHW).

Setting name in my jest.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.

Jest 23: 70s
Jest 24: 105s

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 my babel.config.js, doesnā€™t seem to help.

workaround is to set name in your config

Sorry, where do we set the name? I only have a single config and it is declared in package.json. Adding a name property inside the jest object didnā€™t help.

workaround is to set name in your config

To 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.

System:
OS: Windows 7
CPU: (8) x64 IntelĀ® Coreā„¢ i7-2600 CPU @ 3.40GHz
Binaries:
Node: 11.7.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.13.0 - ~\scoop\apps\yarn\current\Yarn\bin\yarn.CMD npm: 6.5.0 - C:\Program Files\nodejs\npm.CMD