Saturday 10 July 2021

High Jest Heap Memory Usage in JavaScript React Projects

I logged the heap usage while testing with jest, because our jest tests (60+ test cases and 250 tests) are causing a 137 out of memory exception in our ci.

The administration is asking me about jest memory leaks, because the node processes are using arround 5GB RAM while running on the machine.

I was looking into the heap usage of jest, and how to debug that, so I found these Heap Snapshots, that you can take with Chrome Inspektor when you run:

node --inspect-brk --expose-gc ./node_modules/react-scripts/node_modules/.bin/jest --runInBand --logHeapUsage

... or for create-react-app

yarn react-scripts --inspect-brk test --runInBand --logHeapUsage

The outcome of this Heap Usage is very confusing for me, but i found some stuff that I know, for example React-Dom and Lodash.

heap usage image

Is it normal for Lodash and React-Dom etc. to be loaded into that Heap Snapshot multiple times? Or are we implementing major mistakes in our code, that causes these multiloads of lodash, react-dom, etc.

First i was thinking of different library versions, but since the Retained Size is exactly equal in all the lines of the same library, i kind of doubt it.

Questions are:

  • Is it normal for jest to use 5GB RAM by these amounts of tests?
  • Is this multiload of react-dom and lodash and the other libraries normal?
  • Can i look into something else to find the leaks?

Thanks!



from High Jest Heap Memory Usage in JavaScript React Projects

No comments:

Post a Comment