From a0a7989022c56e98ab4f668e95707fe4d6556235 Mon Sep 17 00:00:00 2001 From: Max Lampert Date: Tue, 25 Aug 2026 04:06:06 -0700 Subject: [PATCH] fix(desktop): stamp the start mark at the anchored input event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Blind-review round 18 (Opus xhigh) finding: 26ee8982b moved the measure's origin to the input event's timeStamp but left the start mark at handler-dispatch time, so the Performance panel showed the measure beginning before its own start mark by the input delay — two different switch durations from one instrument. The mark now carries startTime: startedAt, pinned by asserting mark and measure share the anchor. Co-Authored-By: Claude Fable 5 Signed-off-by: Max Lampert --- desktop/src/shared/lib/channelSwitchPerf.test.mjs | 6 ++++++ desktop/src/shared/lib/channelSwitchPerf.ts | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/desktop/src/shared/lib/channelSwitchPerf.test.mjs b/desktop/src/shared/lib/channelSwitchPerf.test.mjs index b5a3872880..90eadea58f 100644 --- a/desktop/src/shared/lib/channelSwitchPerf.test.mjs +++ b/desktop/src/shared/lib/channelSwitchPerf.test.mjs @@ -471,6 +471,9 @@ test("the trace anchors at the input event, not handler dispatch", async () => { globalThis.window.event = { timeStamp: performance.now() - 550 }; begin("aaaa1111aaaa1111"); delete globalThis.window.event; + const startMark = performance + .getEntriesByName("buzz:channel-switch:start") + .at(-1); settle("aaaa1111aaaa1111"); flush(); const measure = performance @@ -481,6 +484,9 @@ test("the trace anchors at the input event, not handler dispatch", async () => { measure.duration >= 550, `input delay must be inside the measure (got ${measure.duration})`, ); + // The mark and the measure must share the anchor, or the Performance + // panel shows two different switch durations for the same switch. + assert.equal(startMark?.startTime, measure.startTime); }); }); diff --git a/desktop/src/shared/lib/channelSwitchPerf.ts b/desktop/src/shared/lib/channelSwitchPerf.ts index 9307daf19a..d970e04bb0 100644 --- a/desktop/src/shared/lib/channelSwitchPerf.ts +++ b/desktop/src/shared/lib/channelSwitchPerf.ts @@ -280,7 +280,13 @@ export function beginChannelSwitchTrace(channelId: string): void { performance.clearMarks(CHANNEL_SWITCH_START_MARK); performance.clearMarks(CHANNEL_SWITCH_SETTLED_MARK); performance.clearMeasures(CHANNEL_SWITCH_MEASURE); - performance.mark(CHANNEL_SWITCH_START_MARK, { detail: { channelId } }); + // startTime keeps the mark on the same anchor as the measure — without it + // the Performance panel would show the measure starting before its own + // start mark by the input delay. + performance.mark(CHANNEL_SWITCH_START_MARK, { + detail: { channelId }, + startTime: startedAt, + }); } export function markChannelSwitchRouteCommit(channelId: string): void {