Skip to content

perf(desktop): prefetch the channel window on sidebar hover intent - #6459

Merged
wesbillman merged 1 commit into
perf/switch-tracingfrom
perf/sidebar-hover-prefetch
Aug 21, 2026
Merged

perf(desktop): prefetch the channel window on sidebar hover intent#6459
wesbillman merged 1 commit into
perf/switch-tracingfrom
perf/sidebar-hover-prefetch

Conversation

@Maxwellimus

Copy link
Copy Markdown
Contributor

Based on perf/switch-tracing — retarget to main after it merges. (Shares the message-window queryFn hunk with the tracing instrumentation.)

A deliberate hover on a sidebar channel row (100ms dwell — pointer scrubbing never fires) warms that channel's message window, so the subsequent click paints from cache instead of paying the relay fetch on the switch path. Live traces measured that fetch at 180–310ms per cold channel entry on a real community — this moves it into the hover dwell, ahead of the click.

The window's query options move into a shared factory so the prefetched entry is byte-identical to what the mounted query reads; the prefetch respects the window's staleTime (hovering a fresh channel never refetches) and dedupes with in-flight fetches. Forum channels are excluded, matching the window query's own gating.

The mock bridge gains a head-fetch probe (cursorless window reads) and a regression spec asserts both directions: dwell fetches exactly once before any click; scrubbing across rows fetches nothing.

@Maxwellimus
Maxwellimus force-pushed the perf/sidebar-hover-prefetch branch from 6fdfcb4 to ad98485 Compare August 21, 2026 04:52
@Maxwellimus
Maxwellimus force-pushed the perf/sidebar-hover-prefetch branch 3 times, most recently from 49e260e to 10212a5 Compare August 21, 2026 19:19
@Maxwellimus
Maxwellimus force-pushed the perf/sidebar-hover-prefetch branch from 10212a5 to d3f30e7 Compare August 21, 2026 19:29
@Maxwellimus

Copy link
Copy Markdown
Contributor Author

🤖 Comment from Maxwell's AI agent.

Adversarial review found one P1, fixed and pushed:

P1 — prefetch/gap-refresh dedupe could drop a live-window event. TanStack Query never re-fetches a query whose initial fetch is in flight — invalidateQueries silently adopts the in-flight promise. So when the live subscription established while a hover prefetch was still running, the post-subscription gap refresh could adopt a snapshot fetched before the subscription started, missing any event that landed in between (verified empirically with a QueryClient harness: 1 queryFn call, stale data wins).

Fix in refreshChannelWindowMessages: cancelQueries before invalidateQueries, matching the existing canceled-stale-fetch contract — the refresh now always issues a fetch that starts after the subscription is active. Covered by a new red-first unit test (projectChannelWindow.test.mjs), and the pinned test_canceled_stale_fetch_cannot_overwrite_catch_up_window contract still passes.

Also strengthened the spec per the P2: the mock bridge now exposes a head-fetch completion counter, and the spec requires the prefetch to complete and a message row to paint from the warmed cache — a pending or failed prefetch can no longer pass.

@Maxwellimus
Maxwellimus force-pushed the perf/sidebar-hover-prefetch branch from d3f30e7 to 67a39e6 Compare August 21, 2026 21:16
A deliberate hover on a sidebar channel row (100ms dwell, so pointer
scrubbing never fires) warms that channel's message window, making the
subsequent click a cache hit instead of paying the relay fetch on the
switch path.

The window query options move into a shared factory so the prefetched
entry is byte-identical to what the mounted query reads; the prefetch
respects the window's staleTime, so hovering a fresh channel never
refetches. The mock bridge gains a head-fetch probe (cursorless window
reads) so the regression spec can assert dwell-fetches-once /
scrub-fetches-never.

Signed-off-by: Max Lampert <maxwell@squareup.com>
@Maxwellimus
Maxwellimus force-pushed the perf/sidebar-hover-prefetch branch from 67a39e6 to 9f0d73e Compare August 21, 2026 21:41
@Maxwellimus
Maxwellimus marked this pull request as ready for review August 21, 2026 22:35
@Maxwellimus
Maxwellimus requested a review from a team as a code owner August 21, 2026 22:35
@Maxwellimus
Maxwellimus requested a review from wesbillman August 21, 2026 22:35

@wesbillman wesbillman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carl, an automated reviewer, commenting via Wes’s GitHub account.

Reviewed stacked exact head 9f0d73ea2431f8f5e8a87b05a54ca0dc59b5614a against base a5e8e530b9be277691589b616a1264953cc79799. No blocking defect found in hover-intent cleanup, forum exclusion, shared query options, subscription establishment, cancellation, or post-subscription invalidation. Focused window/dwell validation passed 14/14 and the exact-head diff check was clean.

@wesbillman
wesbillman merged commit c2e89e6 into perf/switch-tracing Aug 21, 2026
23 checks passed
@wesbillman
wesbillman deleted the perf/sidebar-hover-prefetch branch August 21, 2026 23:40
@Maxwellimus

Copy link
Copy Markdown
Contributor Author

🤖 Comment from Maxwell's AI agent. Heads-up: this merge landed on the stacked base perf/switch-tracing, and a force-push of that base minutes later (carrying the review-requested P1 fixes for #6455) unknowingly overwrote the squash commit — so although this PR shows merged, its content is not on the base branch. Recreated as #6534 (identical diff, verified byte-for-byte), stacked on #6455 as before; it should merge after #6455 lands and gets retargeted to main. Apologies for the churn — the force-push should have checked for fresh merges into the base first.

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.

2 participants