-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Very poor performance on basic tests #7963
Comments
Your repo takes way less time for me: On Windows, startup performance (of any Node process and especially if you do a lot of IO) will always be noticeably slower. You can try upgrading the Node version to 10 or 11 (8 is quite old), I'd expect a 10-20% speedup coming from that. |
Test: 8-10ms Reruns are very erratic if the rerun was triggered by a file change: Test: 2-14ms If it was triggered manually then it is pretty consistent with the first run. Interestingly, if I run with As a side note, my runs seems to have been quite a bit faster than yours despite this machine having pretty dated hardware. That's pretty strange in itself.
|
To give you a bit of background, I was trying to set up the test environment on my work laptop and I noticed that my React tests were way to slow. That's when I've discovered the poor performance. I've also tested this on Linux and it's 2x as fast, but still, 3seconds on re-run for some basic tests it's too much. It's weird that Jest reports that a test runs in 10ms but the reported time is 5seconds. Even on my work laptop, running the tests on create-react-app are slow, on re-run: I guess this issue is a duplicate of #7619 and #6694 so most likely it can be closed. |
Mocha doesn't take 4 seconds to initialise in this case. I changed your test to do
Which by the way, if you add another test it doesn't take 173ms * 2 to run. I've never seen a testing framework that takes more than 500ms to perform a single equality check. There must be some configuration option we can set here, and if there is, I would like to make the case for it to be in the defaults. |
Just copied the original test 50 times to make sure. Results:
|
I tried this out on my Mac and got run times of 3-4s, so a bit closer to what you are describing. There is nothing that takes way longer than expected in the profile though, as I said it's just that IO performance is very OS-dependent, most of this is |
Also, I noticed that watch mode is not running |
After some investigation, the reason why Jest does not run the test
I don't have a good solution to this other than making the threshold more generous right now |
Can you test with node worker threads? Still some overhead, but maybe not so much |
@SimenB no noticeable change. |
( |
There's no mechanism in place to reuse workers across watch runs, is there? Would it be unsafe to do so in case there is some kind of leftover state in the worker? |
Workers are always reused, do you mean the sandbox? If so, no - we want every test to run in isolation However, we want to lift jasmine/circus out of the sandbox and inject some integration points. Might help? |
This is (like some other issues mentioned) definitely a regression introduced in 23.0.0 |
That should be fixed - the worker pool should be reused. Could you bisect? |
Will do, but it's not what causes the performance issue here. After quite a bit of profiling I've determined the culprit to be |
Really? Interesting! Looking forward to the analysis 🙂 |
Still no conclusion? :( |
any updates now that |
Seeing as it's a major, we'll probably upgrade in Jest 25 to be on the safe side |
@SimenB i took a look in diagonal to all the posts @jeysal posted. great work!! questions
|
Assuming no breaking changes, you can use yarn resolutions to test yourself. https://yarnpkg.com/lang/en/docs/selective-version-resolutions/ |
I tried upgrading from v24.9.0 to v26.6.3, and found a slight performance decrease (test suite went from about 17s to 20s). Most of the extra time was at the beginning, there's still a solid 8 to 10 second delay before the first test starts running. There was also an additional pause of about a second or two at the end, after reporting coverage stats, which wasn't there in the earlier version. I don't know much about profiling, but I read this thread with interest because I was hoping to get my front-end tests to run something closer to as fast as my backend (python) tests, which run in about 3s for an enormously larger and more complicated application. I run a Ubuntu VM on windows, node v12.20.0. |
I too have been struggling with Jest performance on our production react app. I have been working to try and implement a "Red Green Refactor" code workflow in our production code base, but the time taken to run tests severely impacts the ability to do this flow efficiently. I have created a repo to explore this further and try to find other options to improve the performance. See https://github.com/trenttobler/ts-unit-test-loadtesting Also in this project is second folder with identical tests, except using a mocha+chai+nyc setup to provide evidence that faster testing time should in theory be possible. I'm looking for any suggestions on strategies or approaches that can be applied to this project, specifically, to get the jest run time to somewhat closer to mocha. This test repository / suite is large (~27K individual assertions), but simulates the scope and raw test counts I'm targeting in our production app.
Note: I created the jest test folder using I welcome any help, suggestions, or advice for strategies or techniques to improve the jest performance and get closer to the mocha+chai+nyc timings. UPDATE: using a '--watch' model, using git commits to control test coverage, got the original tests to almost acceptable rates (~10 seconds for test and coverage report) I would prefer something on the order of 1-2 seconds, but I think this is something we can at least work with. |
@Moumouls thank you for the link ! I managed to get a .cpuprofile file with "node --cpu-prof ./node_modules/.bin/react-scripts..." but it only shows the calls up to "spawnSync", not what happens in the worker processes. Could you be more specific about how you got those flamegraphs ? |
@mlarcher, I've fought with the exact same thing yesterday. There seems to be a bug in Chrome right now. But I got it to work using the latest Chrome Beta version. |
It appeared that create-react-app was making things harder than it should. After ejecting, I was able to run jest directly (with const execArgv = process.execArgv.filter(value=>!value.includes('inspect-brk'));
const randromNumber = Math.floor(Math.random() * 9 + 1);
execArgv.push("--inspect-brk=:700" + randromNumber); and allowing those ports to be discovered by chrome devTools by declaring them in "Discover network targets" Now to dig into the output and try to figure out where the time is spent 🤠 |
Add the possibility to run react as a BUILT VERSION instead as development version to avoid all the validations that react does when one do: NPM START |
Any chance of this being fixed? |
2 years have gone since I created this issue #7619 I believe the only way to fix this is just to use Mocha/Chai/Jasmine... or anything else but Jest! :/ |
I used --maxWorkers=1
Saludos.
Ing. Rebeca López Reynoso
cel. 04455-
3294-6671
Le lun. 15 mars 2021 à 11:39, Nick ***@***.***> a écrit :
… Any chance of this being fixed?
I am struggling with slow jest on a Windows 10 + Webstorm + WSL2 Ubuntu
node interpreter.
For me it takes more than 3 minutes to run a single test with
"isolatedModules": true
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#7963 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAG5GYVBIGS4CY7P7OTGMN3TDZA5HANCNFSM4GZXKNIA>
.
|
@RebecaLozrey I think this blog post covers the details better. I set my config to
Gave me some improvement. |
I have same problem with testing speed (time result in pic) i try to configure package.json to add: |
We found the most improvement by using something like
to run all the specs as one file on our CI environment. Naturally we had lots of tests leaking into one another using this method, but after cleaning that up and following the suggestion from this thead #9457 (comment) in a beforeEach, we reduced our test time by a factor of about 5 (angular 12, >300 spec files and >3000 tests in total). |
From me, when using jest to run my unittests, there are 2 problems I've faced with:
My current approach are:
Hope that jest will introduce us a way to cache imported modules to share access our tests, instead of require it again and again on each test file. |
Same problem here with tests finishing in milliseconds, but the test file taking a very long time to finish. |
Same problem... I tried to increase the number of workers but the high time keeps 🙁 |
Read my post if is still there
…On Fri, Jan 6, 2023, 1:41 PM Reinaldo Teixeira ***@***.***> wrote:
Same problem... I tried to increase the number of workers but the high
time keeps 🙁
—
Reply to this email directly, view it on GitHub
<#7963 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAG5GYTCIEOCYMBLQEDEBNDWRBYQDANCNFSM4GZXKNIA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
any update on this issue :( |
Also having this problem I've created a simple example to check if the problem was my repo and seems that a fresh jest/babel/testing library had the same problem See babel.config.jsSome Javascriptmodule.exports = { presets: ["@babel/preset-env", "@babel/preset-react"] }; See jest.config.jsI'm testing with node environment and jsx environmentjest-node.config.jsmodule.exports = {
slowTestThreshold: 0,
testEnvironment: "node",
testMatch: ["<rootDir>/**/*.spec.jsx", "<rootDir>/**/*.spec.js"],
moduleDirectories: ["node_modules"],
testPathIgnorePatterns: ["<rootDir>/node_modules/"],
}; jest-jsx.config.jsmodule.exports = {
transform: {
"^.+\\.(js|jsx|ts|tsx)$": "babel-jest",
},
slowTestThreshold: 0,
testEnvironment: "jsdom",
setupFilesAfterEnv: ["<rootDir>/setup.js"],
testMatch: ["<rootDir>/**/*.spec.jsx", "<rootDir>/**/*.spec.js"],
moduleDirectories: ["node_modules"],
testPathIgnorePatterns: ["<rootDir>/node_modules/"],
}; My SpecsNo Jsxdescribe("testing", () => {
it("slow spec", () => {
expect(1).toBe(2);
});
}); Jsximport React from "react";
import { render, screen } from "@testing-library/react";
const Test = () => {
return (
<>
<span data-testid="not-empty">
<span data-testid="empty"></span>
</span>
</>
);
};
test("uses jest-dom", () => {
render(<Test />);
expect(screen.queryByTestId("not-empty")).toBeEmptyDOMElement();
}); Results
I'm using those two commands
NodeJSXAs you can see a simple spec with just a I also tried to run both node/jsx two times to check if was a startup problem or maybe jest caching, the specs decreased the time but not even closes to the time of the test itself Does anyone know why is it happening? |
🐛 Bug Report
I've created a simple test with no configuration. You can find it here. It takes 7.6 seconds just to start jest, and then, on file change, it takes 5 seconds to re-run.
There's clearly something wrong here.
Mocha and Chai, for example, start in around 4 seconds, but afterward, the re-run is almost instant.
It's weird that Jest reports that the test takes 14ms but shows me the result in 5 seconds.
On top of this, if you add more basic tests, the time just seems to go up.
To Reproduce
Clone my minimal repository,
yarn install
andyarn test
.Expected behavior
It should be faster than this.
Link to repl or repo (highly encouraged)
https://github.com/cozmy/jest-performance
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: