Skip to content

perf(threads): read to the unread frontier in one thread load - #3822

Draft
kalvinnchau wants to merge 3 commits into
mainfrom
peon/perf-thread-unread-frontier
Draft

kalvinnchau wants to merge 3 commits into
mainfrom
peon/perf-thread-unread-frontier

Conversation

@kalvinnchau

@kalvinnchau kalvinnchau commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When a thread with unread replies opens, the reader pages older until it reaches the first unread reply, and it keeps the thread hidden until then. Each older page was a separate loadMore() started by the panel's positioning decision. Each of those loads first re-read the thread root, so a 200-reply unread thread made four serial root reads and four serial 50-row window reads before showing anything.

Change

  • ThreadView.loadMore(through?) pages within one load until it reaches a reply at or before through. The root is validated once per load, as a retained-range repair already does. ThreadPanel passes the read frontier it already compares against.
  • A frontier load asks for up to four pages per thread_window request. That is 200 rows, the relay's thread_window maximum (MAX_LIMIT in block/buzz crates/buzz-core/src/thread_window.rs). Each window counts as the pages it covers, so the load range stays at ten 50-row pages and a long thread still stops at 460 replies.
  • A frontier load requested while a refresh runs keeps its frontier when it replays.
  • New perf cases thread-unread-open-60 and thread-unread-open-200 open a strict-window thread whose replies are all unread.
  • In production-broker mode, the fixture relay held every older page until a test released it, ignoring olderPageDelayMs. The new cases need a modeled round trip, so the policy relay now releases held pages after olderPageDelayMs when it is set. Existing production-broker cases do not set it.

Relay reads per unread open that needs R older replies: before, ⌈R/50⌉ root reads plus ⌈R/50⌉ window reads. Now, 1 root read plus ⌈R/200⌉ window reads. Rows read are unchanged.

Evidence

bin/pnpm perf --scenario thread-unread-open-{60,200} --repeat 3, Chromium, 150 ms modeled round trip, local machine. Main (46a09db) and this branch were run interleaved, two rounds each. Times are median firstRowsMs:

case main this branch
200 replies, --cpu 1 1488 / 1492 ms 978 / 985 ms
200 replies, --cpu 4 4223 / 4227 ms 3643 / 3628 ms
60 replies, --cpu 1 520 / 506 ms 510 / 511 ms
60 replies, --cpu 4 1617 / 1618 ms 1683 / 1626 ms

The 60-reply case needs only one older window, so it is unchanged. At 4× CPU, most of the time that remains is spent mounting every hidden reply row before positioning. This change does not address that.

Validation

  • bin/pnpm check
  • bin/pnpm vitest run src/features/relay/thread-window.test.ts src/features/relay/threads.test.ts src/features/messages/ThreadPanel.test.tsx: 186 passed. New thread-window tests cover:
    • a frontier load that reads the root once and fetches one 200-row window;
    • a frontier load queued behind a refresh, which fails without the queue change;
    • a frontier load on a 500-reply thread, which stops at the ten-page range: windows of 200, 200 and 50, limited, 460 replies.
  • bin/pnpm test:browser on thread-unread, thread-window, thread-opening, inbox-tabs and inbox-live-read specs, Chromium and WebKit: 88 passed.

Known limitation: if a frontier load fails partway, the rows it read stay in the view, but its cursor does not advance. Retry re-reads those pages.

kalvinnchau and others added 3 commits November 17, 2026 22:55
opening a thread with unread replies paged older one load per positioning
decision, and every load re-read the thread root first. loadMore now takes
the read frontier and pages until it reaches a reply at or before it, so the
root is validated once per open instead of once per page.

adds thread-unread-open-60/200 perf cases. the production-broker fixture now
honors olderPageDelayMs instead of holding older pages until a test releases
them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kalvin Chau <kalvin@block.xyz>
a load to the read frontier now asks for up to four pages per thread_window
request, the relay's 200-row maximum, and counts each window as the pages it
covers. the load range stays ten pages of 50 rows, so a long thread still
stops at the same 460 replies, in fewer serial round trips.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kalvin Chau <kalvin@block.xyz>
thread panel now asks the unread store for a thread's read-through time; give the remaining session fakes that mount it a stub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kalvin Chau <kalvin@block.xyz>

This branch has not been deployed

No deployments
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.

1 participant