🧠 perf: Recycle Backend Jest Workers Past 1GB (#17098)

A backend jest worker keeps every module and transform it has loaded for its whole life and grows past three gigabytes on a packages/api shard. Share a 1GB workerIdleMemoryLimit from config/jest.workers.cjs and apply it to api, packages/api and data-schemas, as the client config already does.
This commit is contained in:
Marco Beretta 2026-10-16 22:15:10 +02:00 • committed by GitHub
parent 55f39996b0
commit 346dd274d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 4 deletions

View file

@ -1,4 +1,4 @@
const { maxWorkers } = require('../config/jest.workers.cjs');
const { maxWorkers, workerIdleMemoryLimit } = require('../config/jest.workers.cjs');
const esModules = [
'openid-client',
@ -25,6 +25,7 @@ module.exports = {
roots: ['<rootDir>'],
coverageDirectory: 'coverage',
maxWorkers,
workerIdleMemoryLimit,
testTimeout: 30000, // 30 seconds timeout for all tests
setupFiles: ['./test/jestSetup.js', './test/__mocks__/logger.js'],
moduleNameMapper: {

View file

@ -27,4 +27,13 @@ function resolveMaxWorkers() {
return Math.max(CI_MIN_WORKERS, Math.floor(cpuCount() / 2));
}
module.exports = { maxWorkers: resolveMaxWorkers() };
/**
* A worker keeps every module it has required and every transform it has run for
* its whole life, so on the backend suites one worker grows past three gigabytes.
* Jest restarts a worker between test files once it exceeds this limit.
*/
const workerIdleMemoryLimit = '1GB';
const maxWorkers = resolveMaxWorkers();
module.exports = { maxWorkers, workerIdleMemoryLimit };

View file

@ -1,4 +1,4 @@
import { maxWorkers } from '../../config/jest.workers.cjs';
import { maxWorkers, workerIdleMemoryLimit } from '../../config/jest.workers.cjs';
const esModules = [
'@langchain/langgraph',
@ -56,6 +56,7 @@ export default {
// },
setupFiles: ['<rootDir>/jest.setup.cjs', '<rootDir>/../../config/jest.setup.logging.cjs'],
maxWorkers,
workerIdleMemoryLimit,
restoreMocks: true,
testTimeout: 15000,
};

View file

@ -1,4 +1,4 @@
import { maxWorkers } from '../../config/jest.workers.cjs';
import { maxWorkers, workerIdleMemoryLimit } from '../../config/jest.workers.cjs';
export default {
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!<rootDir>/node_modules/'],
@ -26,6 +26,7 @@ export default {
globalSetup: '<rootDir>/jest.globalSetup.mjs',
setupFiles: ['<rootDir>/../../config/jest.setup.logging.cjs'],
maxWorkers,
workerIdleMemoryLimit,
restoreMocks: true,
testTimeout: 15000,
};