-
Notifications
You must be signed in to change notification settings - Fork 455
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
Seems to be much slower than Mocha #280
Comments
@paldepind thanks for creating the repo to test on. I tried this out and ts-jest does seem slower. I'm getting results of 7s and 14s for the two tests on a test machine. I definitely want to see this improve! Note: This issue is not the same as #259. The repo linked in this issue takes the same time for ts-jest versions 20.0.4 and 20.0.7. If you're facing the same issue as #259, please create a minimal repo that reproduces that issue and we can open that issue and work on it |
Thank you for the reply. It would be awesome if the overhead could be broad down. I'd love to use Jest :)
You're welcome. If having an additional repository to test on might be helpful I can setup Jest on another open source project of mine as well. |
I've looked into this a bit and it seems there's some issue with caching. Even with a bare minimum transformer that just returns valid js code (without any compilation overhead), jest seems to take 8+ seconds on all runs where mocha takes 7s on the first run and 4s for subsequent runs. This can be seen in the js branch of the fork of the above repo I'm not sure this caching issue is caused by the implementation here or if it is something that needs to be fixed in jest |
I've posted a question on stackoverflow to see if we can get some help on this |
@kulshekhar What about opening an issue in the Jest repo? ts-node is clearly very important to Jest (it's mentioned on the front page and in the official docs) so I imagine they'd be willing to help out 😄 Especially if the performance issue is caused by Jest. |
It seems they only want feature requests and bug reports on their issue tracker and I'm not yet sure this is a bug. That's why I've posted on stackoverflow. Hopefully we'll get some help there. Improving the performance of the simple transformer, which does absolutely no work, should help improve things for ts-jest as well. |
I think we can definitely report this to the jest repo directly - it's a reasonably nice small reproduction on stackoverflow. |
I just tried this without any transformer and the results are the same. The setup in the linked repo is slower with jest than with mocha even without ts-jest. I think this issue should be closed and one opened in the Jest repo. @paldepind thoughts? |
We've identified the issue with ts-jest's caching implementation: in This results in an expensive walk of the entire source directory for each typescript file in the source directory, causing exponential growth in running time as a codebase expands. With our large codebase, this caused a no-op test to take more than 7 seconds to complete. I'll submit a patch shortly that caches in |
After further profiling, it seems that |
I suspect that this particular improvement might have been due to #292 which was published in 20.0.10. Other users have reported a similar improvement (see #259) A quick way of confirming/refuting this would be to test against 20.0.9. |
I'm closing this because, at this stage, it looks like this can't be fixed in ts-jest. We can use this issue to continue the discussion and, if necessary, reopen it down the road. |
@kulshekhar Should I open a bug in the Jest repo? |
@paldepind It might help. I'll leave my fork of your repo up if it helps. The |
Would love a PR with the performance implications you're suggesting @tvald |
Further investigation shows that the jump from 45s to 10s was due to sourcemap caching on subsequent runs thanks to #292. 10s is still fairly lengthy for this particular test, so we'll continue to investigate in our spare time. (35s for sourcemaps is also rather hefty, even if only on first run.) |
Our final conclusion is that there's simply a lot of overhead with large codebases.
|
Guess there's nothing more we can do here then. |
I currently use a testing setup for my projects that uses Mocha, ts-node, and nyc. In several of them I've tried switching to Jest. But ts-jest is consistently significantly slower 😢
I've added Jest to this project where you can see the difference.
These are the times I'm seeing in the project:
time npm test
4.05 secondstime npm run test-jest
12.34 secondsNote that my tests themselves takes about 3-4 seconds. So Mocha adds a very small overhead where Jest is noticeably slower. I've tried in larger projects as well where the difference is even bigger.
For your convenience, here are the commands to reproduce:
The text was updated successfully, but these errors were encountered: