Skip to content

Commit 0ce5e0f

Browse files
committed
Added a function to get the maxOldSpaceSize
1 parent d5cd1c7 commit 0ce5e0f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/core/package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"./v3/workers": "./src/v3/workers/index.ts",
6060
"./v3/schemas": "./src/v3/schemas/index.ts",
6161
"./v3/runEngineWorker": "./src/v3/runEngineWorker/index.ts",
62-
"./v3/checkpoints": "./src/v3/checkpoints/index.ts"
62+
"./v3/checkpoints": "./src/v3/checkpoints/index.ts",
63+
"./v3/machines": "./src/v3/machines/index.ts"
6364
},
6465
"sourceDialects": [
6566
"@triggerdotdev/source"
@@ -180,6 +181,9 @@
180181
],
181182
"v3/checkpoints": [
182183
"dist/commonjs/v3/checkpoints/index.d.ts"
184+
],
185+
"v3/machines": [
186+
"dist/commonjs/v3/machines/index.d.ts"
183187
]
184188
}
185189
},
@@ -673,6 +677,17 @@
673677
"types": "./dist/commonjs/v3/checkpoints/index.d.ts",
674678
"default": "./dist/commonjs/v3/checkpoints/index.js"
675679
}
680+
},
681+
"./v3/machines": {
682+
"import": {
683+
"@triggerdotdev/source": "./src/v3/machines/index.ts",
684+
"types": "./dist/esm/v3/machines/index.d.ts",
685+
"default": "./dist/esm/v3/machines/index.js"
686+
},
687+
"require": {
688+
"types": "./dist/commonjs/v3/machines/index.d.ts",
689+
"default": "./dist/commonjs/v3/machines/index.js"
690+
}
676691
}
677692
},
678693
"type": "module",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { MachinePreset } from "../schemas/common.js";
2+
3+
/**
4+
* Returns a value to be used for `--max-old-space-size`. It is in MiB.
5+
* Setting this correctly means V8 spends more times running Garbage Collection (GC).
6+
* It won't eliminate crashes but it will help avoid them.
7+
* @param {MachinePreset} machine - The machine preset configuration containing memory specifications
8+
* @param {number} [overhead=0.2] - The memory overhead factor (0.2 = 20% reserved for system operations)
9+
* @returns {number} The calculated max old space size in MiB
10+
*/
11+
export function maxOldSpaceSizeForMachine(machine: MachinePreset, overhead = 0.2) {
12+
return machine.memory * 1_024 * (1 - overhead);
13+
}

0 commit comments

Comments
 (0)