Repository navigation
perf(flow-chat): optimize long-round streaming projection and scroll rendering - #3778
Merged
bobleer merged 11 commits intoNov 7, 2026
Merged
Conversation
…rendering Keep settled ModelRound projections, FlowGroupData references, group indexes, search sources, and retained-byte estimates cached across streaming flushes, avoid redundant virtualizer RAF budget commits and unwatched viewport snapshot reads, and add categorized long-round benchmarks.
Raing5Days
force-pushed
the
perf/long-round-scroll-and-render
branch
from
November 6, 2026 12:51
e4130df to
e7f9534
Compare
Desktop chat Markdown now parses GFM with singleTilde disabled, so ranges such as ~5 min or 1~3 stay literal. The remote-control chat still struck them through, so the same transcript read differently on the phone. Apply the same option to both mobile chat renderers through a mobile-local constant; mobile-web must not import Web UI modules.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduce repeated Web UI FlowChat projection work during long streaming turns while preserving settled row identities, history eviction, group ownership and runtime replay repair. Restore model-round chronology when host completion fills gaps in a partial client checkpoint, so final output stays after earlier tool calls. Preserve narrative row measurements through completion and keep single range tildes literal in chat Markdown.
Cache immutable round grouping, lifecycle, merged groups and receive-feedback keys with weak source ownership. Search retains only per-view match metadata; lowercase text is temporary, and closing search clears its cache.
Reuse settled projection prefixes and reconcile unchanged
VirtualItem/FlowGroupDataobjects. Steering, merged retries and interrupted-turn recovery also retain stable display-round identities.Give each live store, history projection and side panel its own streaming-prefix state and warm transcript
WeakMap. Share immutable completed-Turn projections weakly, with separate normal/background presentations; adding a newer Turn does not rebuild unchanged completed rows. All callers, including benchmarks and test fixtures, explicitly create their projector; there is no module-wide mutable projection entry point. Removed and settled Turns are pruned from active reconciliation state; clearing the presentation store releases warm projections. Equal session IDs from different source objects stay isolated.Rebuild changed group indexes from cached row groups to preserve last-alias / first-member ownership, including when a shadowing tail is removed. Inline group caches use group identity instead of list position.
Coalesce repeated drops for an unknown session only after recording its replay gap. Registration restores normal repair requests; unknown sessions are not assumed to be internal background work.
Skip unused viewport snapshots, share needed scroll geometry between anchor capture and snapshot publication, and clean up detached virtualizer rows even when no replacement rows attach. Refresh surviving rows' measurement indexes on every commit, including live prepends and history tail arrivals, so delayed ResizeObserver callbacks resize the correct key. Suspended mounts remain pending until a resumed commit can observe them, including across origin changes; disconnected pending rows are discarded. The recovery frame explicitly requests a commit even when the restored dimensions are unchanged and streaming has ended, without waiting for output, resize or scrolling.
At Runtime completion, merge round metadata by stable ID and order the current generation by its journal. Sparse or suffix-only client checkpoints cannot push missing earlier rounds behind the final answer; prior generations and other retained records survive.
Add a categorized performance harness and regression coverage for cached/full projection equivalence, interior updates, rollback, completion, legacy retry/recovery, shared references, group aliases and DOM cleanup.
Keep mounted narrative keys and measured heights when completion replaces client stream IDs with host IDs. Matching stays local to the same ordered round and attempt; canonical data/search IDs remain host-owned, and bookmarks use canonical IDs across reopen.
Configure conversation GFM parsing to require double tildes for strikethrough, preserving numeric ranges and escapes consistently across streaming, completed, math and Worker/cache paths.
Align native Android/iOS and HarmonyOS chat tildes with desktop Windows/macOS and mobile-web. Native renderers now support double-tilde deletion, preserve single ranges and escapes, reject longer delimiter runs, and use parsed inline text for plain formatting without a second parse. Existing transcript payloads stay unchanged.
Type and Areas
Performance / correctness / tests. Web UI FlowChat, native/mobile-web chat Markdown, the retained-memory estimator and the shared Rust SessionManager completion merge; no wire protocol or persisted schema changes.
Motivation / Impact
Streaming previously rebuilt settled round projections and invalidated downstream timeline and renderer caches. The long-round fixture (10–300 rounds, 20 flushes) retains 97.7% settled VirtualItem reuse and 94.6% settled TimelineBlock reuse after the correctness fixes. The harness now asserts both reuse ratios above 90%; content equivalence is tested separately across 150 deterministic sequences of eight updates (1,200 comparisons), including thinking and tool-parameter streaming. Interleaving history and a streaming side session retains the same 97.7% live row reuse as a single view.
The retained-byte estimator deliberately remains the original shared-reference-aware graph walk. A completed-round prefix does not prove immutable interior members or disjoint referenced objects; the attempted prefix shortcut undercounted resumed turns and retained evicted history. Production already caches immutable whole-Turn estimates and coalesces active-history accounting at 500 ms.
Local diagnostic measurements on the same machine (median of three samples after one warm-up, original PR head
89b1f9159versusc4eb70f40):These supplied-data measurements describe this fixture, not native WebView frame rate or production latency. The earlier retained-byte “100x+” and combined-pipeline speedup claims do not apply to the corrected estimator and have been removed.
Verification
Native/mobile tilde follow-up: 10 shared JVM tests, 21 HarmonyOS parser/serializer/streaming tests, 19 mobile-web component tests and 101 desktop Markdown tests passed. The shared Kotlin and HarmonyOS regressions fail before the fix; mobile-web tests now render range/escape/code/delimiter cases with the production GFM options, including the math parser.
Android Debug APK build, HarmonyOS ArkTS compile, iOS Debug XCFramework generation, iOS app Swift type-check against the generated simulator framework, mobile-web type-check, mobile UI generated-contract check and HarmonyOS architecture check passed. These are local compile/fixture checks, not native-device or live remote evidence.
Local validation limits: full iOS Xcode app build is blocked by the installed Xcode platform/destination setup; HarmonyOS signed HAP packaging lacks local signing configuration.
mobile:architecturereports the same three pre-existing entries on the unchangedf0a4de24cbaseline (a transport test reaching HarmonyOS and two default constructor arguments); no guard or baseline was weakened.Latest Markdown/settlement follow-up: 12 files, 304 tests passed, plus
check:web, changed-production-file ESLint andgit diff --check. Three Markdown regressions fail before the parser change. Four local/simulated-Peer follow/reader cases fail when the identity handoff is disabled and pass with it; they check retained nodes and every frame, canonical bookmark capture/restore and reading-position reopening. The pre-fix geometry fixture showed a 92px drop followed by an eased return.Round-order follow-up: 17 Rust tests passed with
--no-default-features --features agent-runtime,git, covering 64 checkpoint subsets/orders, idempotency, legacy record round trips, interrupted generations and headless completion/reload. Two new regression tests fail before the fix.A read-only diagnostic using an affected local record reproduced the wrong persisted order and verified that canonical round-ID ordering places its final response last through frontend hydration and projection. No private transcript was added to the repository.
pnpm run check:web— passed, including TypeScript and appearance/theme governance checks.Previous viewport-recovery follow-up: projection Store, virtualizer and VirtualMessageList regressions — 14 files, 322 tests passed. Four real-controller/supplied-geometry cases reproduce same-size resume without output, manual re-render or scroll on local/simulated Peer surfaces in live/history layouts; all fail at
85b888362and pass with the recovery commit.Previous broader FlowChat/session/virtualizer pass at
85b888362— 23 files, 722 tests passed, including the legacy Store, performance harness and live/history/side-panel checks.node --test tests/e2e/scripts/sync-work-diagnostic.test.mjs— 4 tests passed; the production source transform includes the currentprojectSessionItemsprobe. Native diagnostic execution was not run.The clear/reopen regression was mutation-checked: disabling the owning Store's cache invalidation makes it fail; restoring invalidation passes.
ESLint on the PR's changed production TypeScript files — passed (test files follow the repository's lint ignore rules).
git diff --check— passed.Added regressions were also exercised against the original PR head,
a727d537dandc4eb70f40to confirm failures in accounting, group ownership, normalization reuse, replay repair, detached-row cleanup, duplicate scroll geometry reads, shifted measurement indexes, interleaved-view cache reuse, suspended-row observation and completed-row reuse after append.Four separate local forced-GC checks confirmed collection of inactive session bodies, removed Turns, discarded projection scopes and obsolete live revisions after completion in another view. These diagnostic checks are kept outside the committed test suite.
Focused commands and their contracts are documented in
src/web-ui/src/flow_chat/components/modern/FLOWCHAT_VERIFICATION.md.Remote coverage: local Rust persistence fixtures, unit/DOM fixtures plus simulated Peer surface repair and equal-ID source isolation. Real SSH/Docker remote workspaces, relay Remote Control, Peer Device Mode connections and Detached Dispatch were not exercised. Native WebView/manual scrolling checks remain pending.
Reviewer Notes
The cache changes depend on FlowChatStore's immutable source-object updates. Caches follow those objects rather than owning retained session bodies. This PR preserves legacy retry display repair and does not rewrite saved conversations.
Checklist