Skip to content

perf(timeline): wire virtual_row_heights_version and zero-alloc row_height::shape (Wave 7c) - #2557

Merged
Hona merged 2 commits into
devfrom
perf/7c-timeline-row-heights-version
Dec 6, 2026
Merged

Hona merged 2 commits into
devfrom
perf/7c-timeline-row-heights-version

Conversation

@Hona

@Hona Hona commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Wires rune#3977's additive El::virtual_row_heights_version(...) (pinned in #2550 at 9e0b8f494) onto crates/session-view/src/timeline/mod.rs so VirtualList::sync_known_heights_checked skips scanning 0..specs.len() on steady-state commits (composer typing, plugin:perf ticks, unchanged warm tab returns), and removes per-row heap allocations inside row_height::shape when real scans run.

flowchart LR
  A["App::view() commit"] --> B{"timeline-fade reused?"}
  B -- "Yes (typing / perf tick)" --> C["sync_known_heights_checked<br/>cached version + env + stamp.reads"]
  C -- "All match" --> D["0 row scans"]
  C -- "Tracked read changed<br/>(expanded / line_hold / MATH_GEN / ...)" --> E["Full scan (zero-alloc shape)"]
  B -- "No (tab switch / transcript / resize)" --> F["row_height::heights_version(...)<br/>(Paused tracked reads)"]
  F --> G{"version == stamp.version<br/>&& env && reads match?"}
  G -- "Yes (warm tab return)" --> D
  G -- "No" --> E
Loading

Changes

  • crates/session-view/src/timeline/mod.rs: Computes row_height::heights_version(...) when s.transcript_version(&id) is Some(tv) and passes .virtual_row_heights_version(hv) beside .virtual_rows_version(version). Unversioned hosts (e.g. story::Host) omit the stamp and keep per-commit scanning.
  • crates/session-view/src/timeline/projection.rs: Adds monotonic Projection::content_generation, incremented on every Projection::new even when same_keys reuses generation (so live, streaming, pt, under, divider, above, below, and top changes invalidate heights_version).
  • crates/session-view/src/recall.rs: Adds globally unique Marks::id (NEXT_MARKS_ID) and monotonic resting_gen: Rc<Cell<u64>>, exposed via Marks::resting_stamp() -> (u64, u64). Bumped on shaped prepare_row change, shaped on_layout_any w/h change, shaped shown LRU eviction, and Marks recreation after forget/retain.
  • crates/session-view/src/timeline/row_height.rs:
    • Adds heights_version(...) guarded by rune::tracked::Paused::new() so reading non-Tracked / version inputs never subscribes timeline-fade to extra cells (media_store, speech, etc.). All Tracked cells read by shape (expanded, code_wrap_overrides, working_state, line_hold, diagrams, media_store, user_status_version, model_name, user_glow_at, MATH_GEN) invalidate per-scan via Rune's tracked_reads (!stamp.reads.changed(), preserved across warm RecentVirtuals restores), avoiding both region over-invalidation and O(disclosures) scans on streaming deltas.
    • Adds UI-thread MATH_GEN: rune::Tracked<()> (note_math_changed(), record_math_read(), math_version()) so finished LaTeX renders invalidate sync_known_heights_checked via stamp.reads (without rebuilding timeline-fade) and via heights_version on tab return.
    • Zero-alloc row_height::shape: stack-buffered with_fold_key ([u8; 96], overflow-safe length check, safe str::from_utf8) with single expanded.get lookup; single-pass borrowed quote_open_stamp; borrowed hash_prompt_meta (short-circuits on narrow(), avoids Vec / ModelRef::clone / uppercase String / redundant backward scan); removes anchor-only fold::is_past; gates rune_kit::math::version(&r.key) on scan.has(FLAG_MATH).
  • crates/session-view/src/lib.rs: Calls timeline::note_math_changed() inside poll_math when rune_kit::math::Client::changed returns true.

Streaming & append_only behavior

  • timeline/mod.rs does not set .virtual_rows_append_only(), so appended_from is None and any row count or key change re-keys (finish_rekey clears heights_cache.stamp) and runs a full scan.
  • Even if .virtual_rows_append_only() is added later, heights_version includes transcript_ver, specs.generation, specs.content_generation, and specs.len(), preventing sync_known_heights_suffix from skipping mutated prior rows.

Input checklist (virtual_row_heights + Marks::height_for + row_height::{layout, shape})

Input Where read heights_version (Paused) sync_known_heights_checked (stamp.reads / KnownHeightsKey)
Session id id mod.rs:300 session shown in timeline-fade inputs
Transcript t mod.rs:300, row_height.rs transcript_ver (None omits stamp) shown_transcript_stamp(shown) in inputs
Row keys & count mod.rs:301 specs.generation, specs.len() same_keys & stamp.item_count == len
Row fields (live, streaming, pt, under, divider, above, below, top) row_height.rs specs.content_generation Captured in reused Rc<Projection>
Recall / Marks (shape, target, LRU, forget/retain) recall.rs marks.resting_stamp() Mounted rows use v.measured[r]
Marks::drawn spring settle recall.rs Parked list keeps v.measured[r] == target.h; evicted list has stamp == None Mounted rows use v.measured[r]
row_height::layout row_height.rs:94-119 layout Captured u64 + Rune KnownHeightsKey
fold::viewport row_height.rs layout Rune KnownHeightsKey exact bound_bits & committed_cross_bits
s.fold_user_messages(), s.assistive(), style::narrow() row_height.rs Hashed directly Tracked<Settings> / inputs / bound_bits
user_comments(id) row_height.rs prompt_extras_generation() Mutators update transcript or variant
user_mentions(id) row_height.rs transcript_ver (note: set_user_mentions in opencode-kit does not call extras_changed(), left out of scope) Parse/preview bumps shown_transcript_stamp
s.diagrams().hidden_in(body) row_height.rs crate::diagram::shown_id() Tracked<Diagrams> in stamp.reads
s.media_store().{markdown,videos}.version() row_height.rs (markdown.version(), videos.version()) Tracked<MediaStore> in stamp.reads
rune_kit::math::version(&r.key) row_height.rs math_version() MATH_GEN (Tracked<()>) in stamp.reads when FLAG_MATH, touched in poll_math
s.expanded(), s.code_wrap_overrides(), s.working_state(), s.line_hold(), s.user_status_version(), s.model_name(), s.user_glow_at() row_height.rs Relies on stamp.reads (zero O(disclosures) scan / zero timeline-fade leak) Tracked reads captured per-scan in stamp.reads (preserved across RecentVirtuals restore)

@Hona
Hona merged commit 1b0bc97 into dev Dec 6, 2026
8 checks passed
@Hona
Hona deleted the perf/7c-timeline-row-heights-version branch December 6, 2026 05:50
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