jest: [Bug]: Memory usage significantly increases in 30.0.0-beta.6 for certain tests

Version

30.0.0-beta.9

Steps to reproduce

Repeat the following using 30.0.0-beta.5 and 30.0.0-beta.6:

  1. Unzip this example repo: test.zip
  2. Install with your preferred package manager.
  3. Start monitoring system memory usage, then run jest.

Expected behavior

Memory usage is about the same between 30.0.0-beta.5 and 30.0.0-beta.6.

Actual behavior

With 30.0.0-beta.5, free memory decreases from 19G to 18G. Tests take about 5 seconds wall clock time.

With 30.0.0-beta.6, free memory decreases from 19G to 9.2G. Tests take about 7 seconds wall clock time.

Additional context

My system I used for testing has 32G memory and 16 CPU cores, which seems to mean Jest runs 10 child processes for the 10 test files included in the example repo.

The setTimeout in the tests is not necessary to reproduce, it’s just there to make it easier to get memory measurements. It also continues to reproduce if the async is removed along with the awaited promise.

The require of the @wordpress/components package seems to be what’s somehow bringing the memory usage way up. I don’t know whether other large packages might do the same thing.

Attempting to measure memory usage within node (e.g. with node --inspect-brk) does not seem to reflect the increased memory usage. Or maybe I was just doing it wrong.

Using --runInBand shows a more modest effect: memory usage is still up in beta.6 compared to beta.5, but since it’s doing one test at a time it doesn’t go up as obviously as it does with 10 workers.

Environment

System:
    OS: Linux 6.12 Debian GNU/Linux 13 (trixie) 13 (trixie)
    CPU: (16) x64 AMD Ryzen 7 7840U w/ Radeon  780M Graphics
  Binaries:
    Node: 22.16.0 - /usr/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.9.2 - /usr/bin/npm
    pnpm: 10.11.1 - /usr/local/bin/pnpm
  npmPackages:
    jest: 30.0.0-beta.6 => 30.0.0-beta.6

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 19 (6 by maintainers)

Most upvoted comments

@JounQin I can confirm that https://pkg.pr.new/jest@15666 brings memory consumption to similar levels as beta 5. Tried both with node 18 and 22.

A colleague of mine pointed out https://github.com/jestjs/jest/issues/15556#issuecomment-2937772844

jest@30.0.0-beta.6 was just published. It should be faster than beta 5, but the default now uses more memory than beta 5. If you’d like the aggressive memory cleanup behavior from beta.5, add testEnvironmentOptions: { globalsCleanupMode: 'hard' } to your Jest config.

Setting that did not help with the issue here.