Description
🐛 Bug Report
Memory usage is high when running ts-jest with jest projects.
To Reproduce
Steps to reproduce the behavior:
git clone [email protected]:richardcornelissen/ts-jest-projects-oom.git
yarn install
yarn test
You will see tests running with a high heap size.
Expected behavior
Much lower memory usage.
Link to repo (highly encouraged)
https://github.com/richardcornelissen/ts-jest-projects-oom
Debug log:
Too large to inline, available at https://raw.githubusercontent.com/richardcornelissen/ts-jest-projects-oom/main/ts-jest.log
envinfo
System:
OS: macOS 10.15.7
CPU: 3,1 GHz Dual-Core Intel Core i5
Npm packages:
jest: 26.5.2
ts-jest: 26.4.1
typescript: 4.0.3
Potential cause
From snapshotting the heap and reading the logs, it looks like initializeLanguageServiceInstance
(see language-service.ts) gets called for each jest project, which keeps a cache of transpiled and instrumented code in memory (memoryCache
) which never gets cleared
Workaround
If you encounter this issue, using ts-jest
's isolatedModules
might help.
In the example repo, run yarn test:isolated-modules
as an example