Repository navigation
Description
Overview
Two frontend performance-benchmark tests intermittently fail bun run test:all under ordinary machine load (no other test failures, no functional regression) — not because the code being measured got slower, but because their thresholds have little to no margin for normal timer/scheduler noise. This has been hit and worked around informally (rerun on a quieter machine) across multiple sessions; it should be fixed rather than continue as tribal knowledge.
Problem Statement
Observed failures from a single bun run test:all run, immediately followed by a clean pass of the same two files run in isolation seconds later on the same otherwise-idle machine:
1. packages/desktop-app/src/tests/patterns/performance.test.ts:250 — "should retrieve patterns by node type within threshold"
AssertionError: expected 0.0011307291000004626 to be less than 0.001
The assertion is expect(avgTime).toBeLessThan(0.001) — a 1-microsecond threshold on an averaged Map.get() lookup, timed via performance.now(). At that scale the assertion is comparing against noise: performance.now()'s practical resolution, GC pauses, and JIT warmup state can each individually account for more than 1μs of variance. The measured overshoot (0.113μs) is within what any of those alone would explain — this is not evidence the lookup got slower.
2. packages/desktop-app/src/tests/performance/architecture-benchmarks.test.ts:196 — "bulk structural operations (100 indent/outdent) complete in <50ms" (fast mode)
AssertionError: expected 63.198374999992666 to be less than 50
This threshold already has a documented coverage-overhead multiplier (budget(), COVERAGE_OVERHEAD_FACTOR = 2) specifically to account for instrumentation slowdown — bulkStructural is 25ms uninstrumented, 50ms under coverage. The failure is a coverage-mode run measuring 63ms against the already-doubled 50ms budget — i.e. even the existing 2x allowance for coverage overhead was not enough headroom under normal (not unusually heavy) machine load.
Root Cause
Both thresholds were set tight enough that they only pass reliably on an idle machine. test:all invokes test:coverage, which runs under instrumentation overhead; neither test currently has enough margin for coverage overhead plus ordinary background load (this session, other daemons/build processes) at the same time.
Proposed Solution
performance.test.ts:250: Either raise the threshold to something realistically measurable at this operation's speed (e.g. low-microseconds to a fraction of a millisecond, still generous for aMap.get()), or switch to a relative/regression-style assertion instead of an absolute sub-microsecond one. A sub-microsecond absolute threshold is not a meaningful regression guard in a JS test runner regardless of load.architecture-benchmarks.test.ts:196(PERF_THRESHOLDS.bulkStructural): IncreaseCOVERAGE_OVERHEAD_FACTORand/or the basebulkStructuralbudget so the coverage-mode threshold has real margin over what a normally-loaded (not idle) dev machine measures — not just enough to pass on a quiet one. Consider whether the existing "Performance regression warning" logged at 80% of threshold (line 199-203) should itself inform the new margin.- For both: keep the underlying "does this stay fast" intent — this is about giving the assertion enough slack to not be a coin flip, not about weakening the actual performance target.
architecture-benchmarks.test.tsalready models this distinction (ARCHITECTURE_TARGETSvs.PERF_THRESHOLDS, see its own comment at line 56-61) — extend that pattern rather than just loosening the asserted number without documenting why.
Acceptance Criteria
-
performance.test.ts's registry-lookup threshold no longer fails under ordinary (non-idle) machine load, verified by runningbun run test:allseveral times back-to-back without a targeted retry -
architecture-benchmarks.test.ts'sbulkStructuralthreshold (fast mode, under coverage) has real margin over normal-load measurements, not just idle-machine measurements - Neither change silently raises the threshold so high it stops catching an actual regression — document the reasoning for the new number in a comment, following the existing
ARCHITECTURE_TARGETS/PERF_THRESHOLDSsplit pattern -
bun run test:allpasses with no new failures
Technical Specifications
Reference Files
packages/desktop-app/src/tests/patterns/performance.test.ts: line 250,should retrieve patterns by node type within thresholdpackages/desktop-app/src/tests/performance/architecture-benchmarks.test.ts: lines 84-90 (PERF_THRESHOLDS,budget(),COVERAGE_OVERHEAD_FACTOR), line 196 (bulk structural operationsassertion)
Prior Related Work
c5ac7789(Measure perf assertions against the run that actually executes them (closes #1975) #1976, "Measure perf assertions against the run that actually executes them") already addressed a related class of this problem forarchitecture-benchmarks.test.tsby introducing thebudget()/coverage-overhead split — this issue is that the resulting margin is still not enough under normal (not just heavy) load, not a full regression of that fix.
Related Issues
- None known — filed fresh from an observed flake during unrelated work (Prefill OOM risk on large prompts: re-tune the compute-buffer reserve and engage history compaction on the shared-chat-node path #2227 PR development), not a re-report of an existing issue.
Activity
malibio commentedon Aug 21, 2026
Frontend baseline: 227 test files passed, 4794 tests passed (80.17s).