From a534af791f5b4ed39a97c1728dfbfff07f7f1525 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 23 Sep 2026 19:18:03 +0200 Subject: [PATCH] cultmesh-ts: calibrate the memory test's RSS bound against measured numbers The 5 MiB bound was a guess and false-failed on the fixed code: 200k direct `nextEvent` calls carry their own ~8 MiB RSS noise floor from thread-pool marshaling and promise bookkeeping, even with zero `koffi.alloc` calls in the loop. Measured on Yggdrasil, same build and host, same 200k-call loop: fixed code (0 koffi.alloc calls in the loop): ~8.0 MiB RSS growth pre-fix code (400k koffi.alloc calls, unfreed): ~29.9 MiB RSS growth 18 MiB sits well above the fixed baseline and well below the leaking one, so the test stays robust to ordinary run-to-run noise while still catching the regression. Co-Authored-By: Claude Sonnet 5 --- .../cultmesh-ts/test/realtime-quic-native.test.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/cultmesh-ts/test/realtime-quic-native.test.ts b/packages/cultmesh-ts/test/realtime-quic-native.test.ts index 04aa0ebd..a55d9a40 100644 --- a/packages/cultmesh-ts/test/realtime-quic-native.test.ts +++ b/packages/cultmesh-ts/test/realtime-quic-native.test.ts @@ -242,10 +242,14 @@ test( global.gc(); const before = process.memoryUsage().rss; - // Sized so the old per-call `koffi.alloc` code (~64 B event struct + - // ~4 B int32, plus allocator bookkeeping, well over 53 B/call) clearly - // exceeds the bound below, while the fixed code, which allocates - // nothing per call, stays flat. + // Even with zero JS-side allocation per call, 200k round trips through + // the real native ABI (thread-pool marshaling, promise bookkeeping) + // carry their own non-zero RSS noise floor: measured at ~8 MiB for the + // fixed code (0 `koffi.alloc` calls in the loop) versus ~30 MiB for the + // old per-call `koffi.alloc` code (400k alloc calls, never freed), on + // the same build and host. The bound sits well above the fixed + // baseline and well below the leaking one, so it stays robust to + // ordinary run-to-run noise while still catching the regression. const ITERATIONS = 200_000; for (let i = 0; i < ITERATIONS; i += 1) { await nextEvent(0, null, 0); @@ -254,7 +258,7 @@ test( const after = process.memoryUsage().rss; const growthBytes = after - before; - const BOUND_BYTES = 5 * 1024 * 1024; + const BOUND_BYTES = 18 * 1024 * 1024; assert.ok( growthBytes < BOUND_BYTES, `RSS grew by ${growthBytes} bytes (${(growthBytes / 1024 / 1024).toFixed(2)} MiB) over ` +