Repository navigation
Replies: 2 comments
|
Re-posting the two tables as plain text — the Markdown tables in the original post rendered as one cell per line. Measurement matrix (same session, host
|
|
Withdrawn by the author. The reported slowness turned out to have a different root cause on this machine: the The opening-window change proposed here is not being pursued. Closing this discussion. |
Uh oh!
There was an error while loading. Please reload this page.
Summary
Switching to a long session shows "载入历史" (loading history) for several seconds. The opening
session/followsnapshot is far larger than expected, and the client must parse, assemble, andrender all of it before
openStatebecomesopen.Measured on a 6.66 MB v3 log (24.6 MB raw JSON, 8024 events): the opening snapshot carried
450 records / 1.09 MB, and cold open took 379 ms on the host.
Root cause
HISTORY_PAGE_OPTIONSinpackages/api/session-controller/src/client/sessions/session.ts:turnWindowdominatesmaxMessages.paginate()inpackages/api/session-controller/src/history.tswalks backwards and stops at aturn/startonce both minima are met — so a single long turn returns everything in that turn,
regardless of
maxMessages. On the measured session, the most recent turn alone contained450 events, so
maxMessagesnever triggered.Reducing
maxMessagesalone does not help:maxMessages: 500+turnWindow {50, 2}(current)maxMessages: 120+turnWindow {50, 2}maxMessages: 120, noturnWindowmaxMessages: 80, noturnWindowmaxMessages: 50, noturnWindowmaxMessages: 30, noturnWindowThe client contract already permits a window that begins mid-turn
(
packages/api/session-controller/src/client/contract/session.ts:123:"partial Turn at the window's beginning").
Proposed change
JUMP_PAGE_OPTIONSmust restatemaxMessagesexplicitly: it previously spreadHISTORY_PAGE_OPTIONS, andminMessages: 200 > maxMessagesis rejected byvalidateHistoryWindow()inhistory.ts.Measured effect
Same three sessions, cold / warm / live:
Host cold-read time is unchanged (379 → 418 ms), which is expected: the cold path still
decodes the full log. What shrinks is the work the client does between receiving the snapshot
and flipping
openStatetoopen—replaceWindow()rebuilds every context, then ChatFlowrenders all rows without virtualization.
Secondary observations (not in the patch)
JSON.parses the entire log to serve one tail page(
packages/session-query/session-query/src/cold-read.ts:37,packages/session/session-persistence-jsonl/src/index.ts:992). ~250 ms for a 24 MB log.full-corpus header scans (607 files × ~0.3 ms each) in
prepareStoredMigration().COLD_LOG_MEMO_MAX_ENTRIES = 2andSESSION_QUERY_DEFAULT_PREPARED_SESSION_CACHE_SIZE = 5are small enough that switching among several long sessions repeatedly pays the cold cost.
Trade-off
Fewer messages on first paint: users may need one "加载更早" click. 30 messages was chosen as
the balance point; 50 is a more conservative alternative.
Happy to test a different value if the maintainers prefer another default.
All reactions