From da3c53f52b5333b0bd669064d473bd49d1330ff2 Mon Sep 17 00:00:00 2001 From: Okiki Ojo Date: Sat, 7 Mar 2026 23:56:40 -0500 Subject: [PATCH] test(memory): enhance leak assertion with warmup and stabilized measurement Signed-off-by: Okiki Ojo --- mod_memory_test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mod_memory_test.ts b/mod_memory_test.ts index 0bde481..426f667 100644 --- a/mod_memory_test.ts +++ b/mod_memory_test.ts @@ -99,6 +99,8 @@ function assertNoLeak( thresholdKB = 512, warmupCount = 1_000, ): void { + // Warm up first so the comparison is not polluted by JIT compilation or one- + // time runtime setup. We want to catch retained memory, not startup cost. for (let i = 0; i < warmupCount; i++) fn(); forceGCIfAvailable(); @@ -106,6 +108,9 @@ function assertNoLeak( forceGCIfAvailable(); const after1 = readHeapUsedBytes(); + // Repeating the same workload after the first stabilized measurement makes a + // second-growth delta much more suspicious. By this point, transient setup + // objects should already be gone if nothing is leaking. for (let i = 0; i < iterCount; i++) fn(); forceGCIfAvailable(); const after2 = readHeapUsedBytes(); -- 2.51.2