From 975dc76709a81ebc0b29b7415e64c0e8e383a327 Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Tue, 7 Jul 2026 15:55:24 +0200 Subject: [PATCH] fix(test): constant def count in the wide-flat scaling fixture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The guard's sparse defs scaled WITH the input (one per 2000 lines), so the fixture inherited a slice of the separate per-def sibling-scan cost (O(defs x siblings) — its own tracked finding): an n^2/2000 term that is negligible on clang-macOS but dominant enough on windows-CLANG64 ASan to push LINEAR walk code to a 43x measured ratio, over the 40x bound. Ten defs at fixed positions regardless of size keep the anti-vacuous breadth check while the sibling-scan term stays 10 x n = linear. Measured after the change: fixed code 22x, pre-merge quadratic walk 339x — the discriminator now has ~2x headroom on the green side and ~8x on the red side across all three toolchains measured. Signed-off-by: Martin Vogel --- tests/test_extraction.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_extraction.c b/tests/test_extraction.c index 8ec7671c3..f8228e46a 100644 --- a/tests/test_extraction.c +++ b/tests/test_extraction.c @@ -3418,9 +3418,15 @@ static long extract_wide_flat_ms(int n, int *out_defs) { return -1; } size_t off = 0; + /* CONSTANT def count (10), independent of n: defs that scale WITH n make + * the fixture superlinear through the separate per-def sibling-scan cost + * (O(defs x siblings)) — on windows-CLANG64 ASan that pushed the ratio + * of LINEAR walk code to 43x. Ten spread-out defs keep the breadth check + * honest while the sibling-scan term stays 10 x n = linear. */ + const int def_stride = n / 10; for (int i = 0; i < n; i++) { off += (size_t)snprintf(src + off, cap - off, "// wide filler %d\n", i); - if (i % 2000 == 0) { + if (i % def_stride == 0) { off += (size_t)snprintf(src + off, cap - off, "var wide_a%d = %d;\n", i, i); } } @@ -3467,8 +3473,8 @@ TEST(extract_wide_flat_file_is_linear) { ASSERT_GTE(t_small, 0); ASSERT_GTE(t_big, 0); /* Anti-vacuous guard: the breadth was actually walked at both sizes. */ - ASSERT_GTE(defs_small, 10); - ASSERT_GTE(defs_big, 40); + ASSERT_GTE(defs_small, 8); + ASSERT_GTE(defs_big, 8); fprintf(stderr, " [wide-flat] t(%d)=%ldms t(%d)=%ldms\n", WF_SMALL, t_small, WF_BIG, t_big); long base = t_small > WF_FLOOR_MS ? t_small : WF_FLOOR_MS; if (t_big > WF_RATIO_MAX * base) {