Skip to content

Give flaky performance-benchmark thresholds real margin - #2235

Merged
malibio merged 2 commits into
mainfrom
issue-2233-flaky-perf-thresholds
Aug 21, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-2233-flaky-perf-thresholds

Conversation

@malibio

@malibio malibio commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • performance.test.ts's registry-lookup tests asserted avgTime < 0.001ms (1 microsecond) on averaged Map.get()/Map.has() calls — a threshold that timer resolution, GC pauses, and JIT warmup jitter alone can exceed with no actual regression. Raised to 10 microseconds (get/has) and 20 microseconds (getAllPatterns, which converts Map to Array), documented inline.
  • architecture-benchmarks.test.ts's bulkStructural threshold (fast mode) was 25ms base × COVERAGE_OVERHEAD_FACTOR = 2 = 50ms under coverage, observed failing at 63ms on a normally-loaded (not idle) machine. Raised the fast-mode base to 35ms (→ 70ms under coverage), giving real margin over normal-load measurements while keeping a same-order-of-magnitude bound. Full mode is untouched.
  • Both changes follow the existing ARCHITECTURE_TARGETS/PERF_THRESHOLDS split pattern (issue-mandated) rather than just loosening numbers without documenting why.

Closes #2233.

Test plan

  • bun run test baseline: 227 files / 4794 tests passed
  • Both affected test files run directly and under --coverage, individually and together — pass with real margin (e.g. bulkStructural measured 23ms against a 70ms coverage-mode budget)
  • bun run test:all run twice back-to-back, no flakiness on either previously-flaky assertion
  • bun run quality:fix — no lint/format issues, no unrelated file changes
  • Full pre-push gate (test:all + cargo build + e2e suite) passed

🤖 Generated with Claude Code

https://claude.ai/code/session_014gZjK3rMbXHaA46JgmYbtx

Two thresholds were tight enough to only pass reliably on an idle
machine: performance.test.ts asserted sub-microsecond Map lookups
against a 1us threshold that measurement noise alone could exceed, and
architecture-benchmarks.test.ts's bulkStructural coverage-mode budget
(50ms) had no headroom over normal (not just idle) machine load,
observed failing at 63ms. Raise both with margin, following the
existing PERF_THRESHOLDS/budget() pattern, and document why the new
numbers still catch a real regression.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014gZjK3rMbXHaA46JgmYbtx
@malibio

malibio commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

Net positive, low-risk fix that does what issue #2233 asked for: it replaces noise-level absolute thresholds with reasoned ones and documents the reasoning inline, following the existing ARCHITECTURE_TARGETS/PERF_THRESHOLDS split pattern rather than just bumping numbers until green. Verified the diff directly (git diff origin/main...HEAD) and ran both modified test files — 30/30 pass, and the bulkStructural assertion now logs 12.88ms (target: <35ms) in fast/uninstrumented mode, consistent with the stated reasoning.

Scope is exactly two test files, one commit, no production code touched — appropriately atomic for a threshold-tuning fix.

Requirements Validation (issue #2233 acceptance criteria)

  • performance.test.ts registry-lookup threshold no longer at noise level — 1μs/5μs → 10μs/20μs, all three sub-microsecond assertions (getPattern, hasPattern, getAllPatterns — lines formerly ~250/263/276) converted, not just the one named in the issue body.
  • architecture-benchmarks.test.ts bulkStructural given real margin — fast-mode base 25ms → 35ms (coverage-mode 50ms → 70ms).
  • Reasoning documented in comments following the ARCHITECTURE_TARGETS/PERF_THRESHOLDS split pattern — both changes add multi-line comments explaining why the new number, not just what it is; extends rather than restates the existing pattern.
  • [~] "bun run test:all passes with no new failures, verified back-to-back" — not independently re-verified by me beyond running the two target files directly (30/30 pass). Recommend the author confirm a bun run test:all pass was captured per the issue's explicit verification method before merge, since that's the one criterion that requires the coverage-instrumented path specifically.

Findings

Critical Issues

None.

Suggested Improvements

  • architecture-benchmarks.test.ts — headroom is thin relative to the one observed data point. The issue reports an actual coverage-mode failure at 63ms against the old 50ms budget. The new budget is 70ms — about 11% margin over that single observed failure, not a generous cushion. The comment's own framing ("same order of magnitude") is honest about this, which is good, but if a modestly heavier load recreates a 65-70ms result the flake just moves rather than disappearing. Since this is inherently a "pick a number from one anecdote" problem, this isn't blocking, but if it flakes again shortly after merge, that's a strong signal to revisit with either more samples or a mechanism less sensitive to point-in-time load (e.g., a few warm-up iterations before the timed run, or taking a median over N runs) rather than incrementally raising the constant again.

  • Both files now have two independent, unlinked places to update thresholds by hand (performance.test.ts's new constants vs. the pre-existing PATTERN_DETECTION_THRESHOLD_MS, and PERF_THRESHOLDS vs ARCHITECTURE_TARGETS). Not a defect in this PR — the pattern already existed — but worth a forward-looking note: if a third flake shows up in either file, that's the signal to consider a shared "coverage/load margin" helper instead of hand-tuning each constant independently. Not asking for that here; YAGNI applies until it recurs a third time.

Nitpicks

  • Nit: performance.test.ts:31 — REGISTRY_GET_ALL_THRESHOLD_MS inline comment ("converts Map to Array") duplicates the reasoning already given in the block comment above it (lines 22-29). Harmless, but the block comment could just as easily live directly above the constant it explains rather than above both, since REGISTRY_LOOKUP_THRESHOLD_MS doesn't do a Map→Array conversion and doesn't need that justification.
  • Nit: Neither file's new comments reference the issue number, correctly following the CLAUDE.md rule against embedding issue numbers in code comments — confirmed via grep for #2233/2235, no matches. Calling this out only because it was explicitly worth checking, not because anything is wrong.

Verdict

Approve. This is a well-reasoned, appropriately scoped fix — thresholds are justified with actual measurements and comments explain why, not just what, matching the issue's explicit ask to avoid "loosening until it passes." The one open item (thin headroom on bulkStructural) is worth watching post-merge but isn't a reason to block, since the alternative (guessing a bigger number with no more data) isn't obviously better.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — Approve. See full findings in the comment above. Net positive; no critical issues; one non-blocking margin-thinness note on bulkStructural.

The prior coverage-mode budget (70ms) had only ~11% margin over the
63ms failure that motivated this fix — a single data point isn't a
reliable ceiling. Bump the fast-mode base to 40ms (80ms under
coverage) for ~27% margin while staying well under a real regression
bound (<3.5x the uninstrumented baseline).

Addresses reviewer feedback from PR #2235 review.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014gZjK3rMbXHaA46JgmYbtx
@malibio

malibio commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed Review Feedback

The review came back APPROVE with no Critical or Important findings. Per project policy, ran /address-review unconditionally anyway.

Addressed:

  • 🟢 Widened bulkStructural's coverage-mode margin: fast-mode base 35ms → 40ms (coverage-mode budget 70ms → 80ms), giving ~27% margin over the 63ms observed failure instead of ~11%. A single data point isn't a reliable ceiling, so more headroom is warranted while staying well under a real-regression bound (<3.5x the uninstrumented ~25ms baseline).

Skipped (with reasoning):

  • 🟢 "Two independent threshold constants, consolidate if a third flake shows up" — YAGNI, correctly deferred per the reviewer's own framing.
  • 🟢 "REGISTRY_GET_ALL_THRESHOLD_MS comment duplicates reasoning above it" — reviewed the actual comment; it states a distinct reason (Map→Array conversion cost is why this threshold is 2x the others) not covered by the block comment above, so it's not redundant. No change made.

Re-verified both test files pass individually, together, and under --coverage after the change (bulkStructural measured 22.6ms against the new 80ms coverage-mode budget). Full bun run test (227 files / 4794 tests) and the pre-push gate (test:all + cargo build + e2e) both passed clean.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The only change was widening a numeric safety margin further in the same direction and for the same reason the original review already evaluated and approved — no new logic, no architectural change, no new risk surface. All other feedback was correctly triaged as non-blocking suggestions and either applied or explained.

@malibio
malibio merged commit ad98cc4 into main Aug 21, 2026
@malibio
malibio deleted the issue-2233-flaky-perf-thresholds branch August 21, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two performance-benchmark tests have thresholds too tight for normal machine load, causing intermittent test:all failures

1 participant