Skip to content

When using vmForks the poolOptions.vmThreads.memoryLimit is used to set memory limit #7952

@tomardern

Description

@tomardern

Describe the bug

We've noticed a high heap usage when running our tests.

After much debugging, we noticed that the following code looks for the configuration option for vmThreads even through we have explicitly defined vmForks as the pool to use

I believe it comes down to getWorkerMemoryLimit which has vmThreads hardcoded as the config to read.
https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/utils/memory-limit.ts#L22

export function getWorkerMemoryLimit(config: ResolvedConfig): string | number {
  const memoryLimit = config.poolOptions?.vmThreads?.memoryLimit // <!-- This uses the `vmThreads` even though `pool: vmForks` is used

  if (memoryLimit) {
    return memoryLimit
  }

  return (
    1
    / (config.poolOptions?.vmThreads?.maxThreads
      ?? getDefaultThreadsCount(config))
  )
}

The getWorkerMemoryLimit is called on this line:

https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/node/pools/vmForks.ts#L216

Thanks,

Reproduction

See above.

System Info

System:
    OS: macOS 15.3.2
    CPU: (12) arm64 Apple M4 Pro
    Memory: 1.39 GB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.15.0 - ~/.nvm/versions/node/v22.15.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v18.20.2/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.15.0/bin/npm
  Browsers:
    Chrome: 136.0.7103.93
    Safari: 18.3.1

Used Package Manager

yarn

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions