Skip to content

Commit 9496d17

Browse files
Add GC between groups, process priority, and larger heap for reduced CI variance
- Add explicit globalThis.gc?.() calls between benchmark groups in parser.bench.mjs to force GC before each group starts - Add nice -n -20 process priority on Linux CI (combined with taskset) - Add --max-old-space-size=4096 to reduce GC pressure during benchmarks Co-authored-by: NullVoxPopuli <[email protected]>
1 parent a1123dc commit 9496d17

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

scripts/bench-compare.mjs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,35 @@ try {
9797
console.error(`\n🏎️ Running benchmarks (experiment vs control)…\n`);
9898

9999
const benchScript = join(ROOT, 'tests/parser.bench.mjs');
100-
const benchArgs = ['--expose-gc', benchScript, '--control-dir', CONTROL_DIR];
101-
102-
// CPU pinning on Linux
100+
const benchArgs = [
101+
'--expose-gc',
102+
'--max-old-space-size=4096',
103+
benchScript,
104+
'--control-dir',
105+
CONTROL_DIR,
106+
];
107+
108+
// CPU pinning + process priority on Linux
103109
const IS_LINUX = process.platform === 'linux';
104110
const HAS_TASKSET = IS_LINUX && spawnSync('which', ['taskset'], { stdio: 'pipe' }).status === 0;
105-
106-
const cmd = HAS_TASKSET ? 'taskset' : 'node';
107-
const fullArgs = HAS_TASKSET ? ['-c', '0', 'node', ...benchArgs] : benchArgs;
108-
109-
if (HAS_TASKSET) {
111+
const HAS_NICE = IS_LINUX && spawnSync('which', ['nice'], { stdio: 'pipe' }).status === 0;
112+
113+
let cmd = 'node';
114+
let fullArgs = benchArgs;
115+
116+
if (HAS_TASKSET && HAS_NICE) {
117+
// nice -n -20: highest priority; taskset -c 0: pin to CPU 0
118+
cmd = 'nice';
119+
fullArgs = ['-n', '-20', 'taskset', '-c', '0', 'node', ...benchArgs];
120+
console.error('📌 CPU pinning + high priority enabled (nice -n -20 taskset -c 0)\n');
121+
} else if (HAS_TASKSET) {
122+
cmd = 'taskset';
123+
fullArgs = ['-c', '0', 'node', ...benchArgs];
110124
console.error('📌 CPU pinning enabled (taskset -c 0)\n');
125+
} else if (HAS_NICE) {
126+
cmd = 'nice';
127+
fullArgs = ['-n', '-20', 'node', ...benchArgs];
128+
console.error('📌 High priority enabled (nice -n -20)\n');
111129
}
112130

113131
const result = spawnSync(cmd, fullArgs, {

tests/parser.bench.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ for (const { type, ext, experimentParse, controlParse } of PARSERS) {
9494
const code = FIXTURES[type][size];
9595
const opts = { ...PARSE_OPTIONS, filePath: `${size}${ext}` };
9696

97+
// Force a full GC before each benchmark group to reduce GC-triggered variance
98+
globalThis.gc?.();
99+
97100
if (controlParse) {
98101
// Side-by-side comparison with boxplots
99102
boxplot(() => {

0 commit comments

Comments
 (0)