From afcf3afea125d8858ccada9ed91e7fe641aafd4d Mon Sep 17 00:00:00 2001 From: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com> Date: Sat, 10 Oct 2026 09:44:54 +0000 Subject: [PATCH] test(javascript): check #1495 growth rate instead of wall time The #1495 regression test required 2,000 receiver calls to finish within 2 s. CI shards run with v8 coverage on slower runners: the test took 1.9 s on #1517's run and 3.2-3.6 s on main afterwards, failing every PR. It now compares the fastest of two runs at 1,600 and 400 calls. That ratio is about 5-6x for the fix, with or without coverage, and about 13-14x for the quadratic code before #1517, so the bound of 10 holds on any runner while still catching the regression. Co-Authored-By: Claude Opus 5.5 --- ...tSemanticAnalysis.member_mutations.test.ts | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/domain/javascript/javascriptSemanticAnalysis.member_mutations.test.ts b/src/domain/javascript/javascriptSemanticAnalysis.member_mutations.test.ts index bf7d35c47..c8a6ee158 100644 --- a/src/domain/javascript/javascriptSemanticAnalysis.member_mutations.test.ts +++ b/src/domain/javascript/javascriptSemanticAnalysis.member_mutations.test.ts @@ -629,23 +629,34 @@ describe("results of methods on an escaped receiver", () => { }); it("expands a receiver's methods once rather than once per call (#1495)", () => { - const count = 2000; - const methods = Array.from( - { length: count }, - (_, index) => `m${index}() { return shared; },`, - ).join(" "); - const calls = Array.from( - { length: count }, - (_, index) => `box.m${index}().p${index} = ${index};`, - ).join(" "); - const start = performance.now(); - const value = resultValue( - `const shared = { token: "TOKEN" }; const box = { ${methods} }; ${calls} return [shared.token];`, - ); - expect(performance.now() - start).toBeLessThan(2000); - expect(value).toMatchObject({ + const receiverCalls = (count: number) => { + const methods = Array.from( + { length: count }, + (_, index) => `m${index}() { return shared; },`, + ).join(" "); + const calls = Array.from( + { length: count }, + (_, index) => `box.m${index}().p${index} = ${index};`, + ).join(" "); + return `const shared = { token: "TOKEN" }; const box = { ${methods} }; ${calls} return [shared.token];`; + }; + const fastest = (body: string) => + Math.min( + ...[0, 1].map(() => { + const start = performance.now(); + resultValue(body); + return performance.now() - start; + }), + ); + resultValue(receiverCalls(100)); + // Compare growth rather than wall time, which depends on the runner and on + // coverage instrumentation. Four times the calls costs about 5-6x here; + // re-expanding every method per call cost about 13-14x. + const ratio = fastest(receiverCalls(1600)) / fastest(receiverCalls(400)); + expect(ratio).toBeLessThan(10); + expect(resultValue(receiverCalls(400))).toMatchObject({ status: "array", items: [{ value: { status: "unknown" } }], }); - }, 30000); + }, 60000); });