fix(desktop): discard stale longtask deliveries at perf-sample start

Blind-review round 5 (Fable medium) finding: a longtask trailing switch
N is delivered by the PerformanceObserver in a later task and landed in
switch N+1's freshly reset array, inflating its longtask lines. Drain
takeRecords() and discard before each sample's reset.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Max Lampert <maxwell@squareup.com>
This commit is contained in:
Max Lampert
2026-08-24 21:34:01 -07:00
parent 96817abc2b
commit 083e9489d9

View File

@@ -94,6 +94,10 @@ async function measureSwitch(
__LONGTASKS__: number[];
__LONGTASK_OBSERVER__?: PerformanceObserver;
};
// Discard pending deliveries from BEFORE this sample: a longtask
// trailing the previous switch is delivered in a later task and would
// otherwise land in this sample's fresh array.
store.__LONGTASK_OBSERVER__?.takeRecords();
store.__LONGTASKS__ = [];
const link = document.querySelector<HTMLElement>(
`[data-testid="${args.targetTestId}"]`,