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 {