Skip to content

perf: stop the flaky perf gate false-failing on noisy TUI render allocs - #84

Merged
JAORMX merged 1 commit into
mainfrom
perf-gate-flaky-fix
Jun 17, 2026
Merged

JAORMX merged 1 commit into
mainfrom
perf-gate-flaky-fix

Conversation

@JAORMX

@JAORMX JAORMX commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

What & why

The perf-pr "scenarios (smaller-is-better)" gate was false-failing on noise. It compared one PR run's allocs/op against the single previous-main value on gh-pages at a flat alert-threshold: '102%' with fail-on-alert: true. Two TUI render metrics — tui_scrollback_view/allocs_per_op and tui_scrollback_view_steady/allocs_per_op — were never actually deterministic: gh-pages history shows view swinging ~4.6% and steady ~30% across recent main commits that touched zero TUI code. PR #83 (docs + CI only, no Go) tripped it because the previous-main commit happened to be a low outlier. perf.yml's own comment anticipated exactly this and prescribed the escalation taken here.

Two independent root causes, both fixed

A — Benchmark determinism

AllocsPerOp = total_allocs / b.N, and b.N is chosen from timing (runner-speed-dependent). BenchmarkScrollbackView called appendAssistant(".") every op, growing the live block unboundedly → total allocs superlinear in b.N → allocs/op rose with runner speed.

New reviseAssistant() reducer replaces the live block with a fixed-size, byte-different body each op, through the currentAssistant() rev-bump gateway: the render + join caches still miss every op (the worst-case streaming floor the bench targets is preserved) but the block no longer grows, so allocs/op is b.N-independent.

Guards (both mutation-verified):

  • TestScrollbackReviseAllocsIndependentOfN — fails at Δ=456970 vs ±1 tolerance if reverted to the growth bug.
  • TestScrollbackReviseBustsCacheEveryOp — asserts the join still all-misses, so the bench keeps measuring the hotspot.

B — Gate restructure (the prescribed escalation)

perfconvert now emits a third dedicated advisory suite (-render) carrying only the two noisy render-alloc points; perf.yml runs it with fail-on-alert: false in both jobs. Every deterministic gate stays hard: the render benches' tokens_total + goroutine_delta remain in the smaller suite, non-TUI scenario allocs stay hard, the bigger cache-hit suite is unchanged, and the separate allocsgate-over-task bench gate is untouched. SHA-pins preserved; gh-pages fetch ordering across the now-three github-action-benchmark steps preserved (smaller fetches first; bigger and render use skip-fetch-gh-pages in perf-pr).

C — Docs

perf.yml comments, docs/adr/0019-perf-tracking.md, and the perfconvert + bench doc-comments updated; the "if a 2% false positive ever fires, split…" note flipped to "shipped."

Review & verification

Run through the dev pipeline: architect plan → separate implementer → 4-axis panel (spec / standards / devops-expert / QA test-adequacy) → 1 iteration → commit. Panel verdict: clean, no must-fix. task test (full, -race) green; scoped golangci-lint + actionlint clean; manual perfconvert -render empty-suite round-trip emits a valid [].

Follow-up (optional, not in this PR)

Both render-alloc points went advisory. Once the dashboard shows view's post-fix variance (A should make it near-deterministic), view could be re-tightened to a hard gate — a cheap follow-up.

🤖 Generated with Claude Code

The github-action-benchmark "scenarios (smaller-is-better)" gate compared
one PR run's allocs/op against the single previous-main value at a flat 2%
threshold with fail-on-alert. Two TUI render metrics were never actually
deterministic: gh-pages history showed tui_scrollback_view swinging ~4.6%
and tui_scrollback_view_steady ~30% across commits that touched zero TUI
code. PR #83 (docs+CI only, no Go) false-failed because the previous-main
commit happened to be a low outlier. perf.yml's own comment anticipated
this and prescribed the escalation taken here.

Two independent root causes, both fixed:

A. Benchmark determinism. AllocsPerOp = total_allocs / b.N, and b.N is
   chosen from timing (runner-speed-dependent). BenchmarkScrollbackView
   called appendAssistant(".") every op, growing the live block
   unboundedly -> total allocs superlinear in b.N -> allocs/op rose with
   runner speed. New reviseAssistant() reducer replaces the live block
   with a fixed-SIZE, byte-different body each op through the
   currentAssistant() rev-bump gateway: the render+join caches still MISS
   every op (worst-case streaming floor preserved) but the block does not
   grow, so allocs/op is now b.N-independent. Guarded by
   TestScrollbackReviseAllocsIndependentOfN (mutation-verified: the old
   growth bug fails it at delta=456970 vs +/-1 tolerance) and
   TestScrollbackReviseBustsCacheEveryOp (asserts the join still all-misses
   so the bench keeps measuring the hotspot).

B. Gate restructure. perfconvert now emits a THIRD dedicated advisory
   suite (-render) carrying only the two noisy render-alloc points;
   perf.yml runs it with fail-on-alert:false in both jobs. Every
   deterministic gate stays hard: the render benches' tokens_total and
   goroutine_delta remain in the smaller suite, non-TUI scenario allocs
   stay hard, the bigger cache-hit suite is unchanged, and the
   allocsgate-over-task-bench gate is untouched. SHA-pins preserved;
   gh-pages fetch ordering across the now-three steps preserved (smaller
   fetches first; bigger and render use skip-fetch-gh-pages in perf-pr).

Reviewed via the panel (spec/standards/devops/QA): clean, no must-fix.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@JAORMX
JAORMX merged commit 6a40977 into main Jun 17, 2026
9 checks passed
@JAORMX
JAORMX deleted the perf-gate-flaky-fix branch June 17, 2026 12:12
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.

1 participant