Skip to content

perf(timeline): stop cloning settled turn rows on every streaming update - #2431

Merged
kitlangton merged 1 commit into
devfrom
perf/rc-rowspec-chunks
Dec 4, 2026
Merged

kitlangton merged 1 commit into
devfrom
perf/rc-rowspec-chunks

Conversation

@kitlangton

Copy link
Copy Markdown
Collaborator

Streaming into a long assistant turn no longer clones thousands of settled rows or re-scans the whole turn prefix on every structural update.
Previously, each tool transition or new block in a long turn copied every cached rowspec across all frozen 64-step prefix chunks just to stamp the turn's latest end index and live flag, then re-spaced the entire turn. Rendered rows, vertical rhythm, disclosures, pagination, and multi-server cache isolation stay identical.

❌ Before

  1. A structural delta lands at the end of a long active turn.
  2. Span projection walks every message in the turn from the last prompt to rebuild the full entry slice.
  3. The turn cache skips re-folding unchanged 64-step chunks, ❌ clones all ~3,000 RowSpecs out of them to overwrite end and live, and re-runs divider and rhythm spacing across the whole vector.

✅ After

  1. A structural delta lands at the end of a long active turn.
  2. Span projection fast-forwards past unchanged 64-step prefix chunks straight to the dirty tail cursor.
  3. Frozen prefix chunks stay immutable Rc<[RowSpec]> slices pre-spaced once on creation and shared directly with Projection; mounted rows read current (end, live) from a compact sorted per-turn table on Projection, and unchanged chunk-pair seams reuse their prior seam overrides.
- walk all turn messages -> clone every cached RowSpec to stamp (end, live) -> re-space all rows
+ skip unchanged 64-step chunks -> share Rc<[RowSpec]> slices + reuse seams -> read (end, live) from Projection::turn_bounds

📊 Numbers: 1,506-session synthetic multi-stream workload (2,098-message root transcript with a 1,200-step active turn, 11 concurrent streams, 1 warmup + 7 measured headless runs, 476 steady frames/run on Apple Silicon)

Measure Before (dev) After
cloned_rows_p95 3,021 12 (0 in turn cache; 12 across dirty seams)
projected_msgs_p95 1,352 4
update_p50_ms 2.922 ms 2.194 ms (-24.9%)
update_p95_ms 9.667 ms 8.809 ms (-8.9%)
view_cpu_mean_ms 1.178 ms 0.999 ms (-15.2%)
commit_cpu_mean_ms 2.317 ms 1.845 ms (-20.4%)
input_encode_p50_ms 3.350 ms 2.476 ms (-26.1%)
alloc_mb_p50 / p95 1.409 / 10.823 MB 1.376 / 10.607 MB (timeline-only projection frames: 0.70–1.81 MB)
Debug REGION_WARNINGS 0 0

👀 Read: crates/session-view/src/timeline/turn_cache.rs (prefix's strict c.end < from bound so the fast-forwarded cursor message itself is guaranteed unchanged) and crates/session-view/src/timeline/projection.rs (space_seams reusing seam overrides across Rc::ptr_eq chunk pairs and same_keys skipping Rc::ptr_eq chunks in O(1)). The rest is routine.

🔍 Follow-up to #2400–#2404 streaming frame-cost pass · no user reports · measured across 1 warmup + 7 headless runs (476 steady frames/run) on Apple Silicon

Checks run
  • bash scripts/guardrails.sh: 11/11 passed
  • cargo check --bin opencode-desktop: pass
  • cargo check -p session-view --examples: pass
  • Headless streaming benchmark (--features frame-profile, 1 warmup + 7 runs + debug dev-fast region-reuse check): pass, 0 region warnings

@kitlangton
kitlangton merged commit 145655a into dev Dec 4, 2026
8 checks passed
@kitlangton
kitlangton deleted the perf/rc-rowspec-chunks branch December 4, 2026 15:23
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