Skip to content

Commit 975dc76

Browse files
committed
fix(test): constant def count in the wide-flat scaling fixture
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 <martin.vogel.tech@gmail.com>
1 parent 4630d2a commit 975dc76

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎tests/test_extraction.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3418,9 +3418,15 @@ static long extract_wide_flat_ms(int n, int *out_defs) {
34183418
return -1;
34193419
}
34203420
size_t off = 0;
3421+
/* CONSTANT def count (10), independent of n: defs that scale WITH n make
3422+
* the fixture superlinear through the separate per-def sibling-scan cost
3423+
* (O(defs x siblings)) — on windows-CLANG64 ASan that pushed the ratio
3424+
* of LINEAR walk code to 43x. Ten spread-out defs keep the breadth check
3425+
* honest while the sibling-scan term stays 10 x n = linear. */
3426+
const int def_stride = n / 10;
34213427
for (int i = 0; i < n; i++) {
34223428
off += (size_t)snprintf(src + off, cap - off, "// wide filler %d\n", i);
3423-
if (i % 2000 == 0) {
3429+
if (i % def_stride == 0) {
34243430
off += (size_t)snprintf(src + off, cap - off, "var wide_a%d = %d;\n", i, i);
34253431
}
34263432
}
@@ -3467,8 +3473,8 @@ TEST(extract_wide_flat_file_is_linear) {
34673473
ASSERT_GTE(t_small, 0);
34683474
ASSERT_GTE(t_big, 0);
34693475
/* Anti-vacuous guard: the breadth was actually walked at both sizes. */
3470-
ASSERT_GTE(defs_small, 10);
3471-
ASSERT_GTE(defs_big, 40);
3476+
ASSERT_GTE(defs_small, 8);
3477+
ASSERT_GTE(defs_big, 8);
34723478
fprintf(stderr, " [wide-flat] t(%d)=%ldms t(%d)=%ldms\n", WF_SMALL, t_small, WF_BIG, t_big);
34733479
long base = t_small > WF_FLOOR_MS ? t_small : WF_FLOOR_MS;
34743480
if (t_big > WF_RATIO_MAX * base) {

0 commit comments

Comments
 (0)