Repository navigation
perf(timeline,session-view): eliminate per-frame heap allocation churn during streaming - #2564
Merged
Merged
Conversation
…n during streaming
… compaction memo, and shell tail
…c-churn # Conflicts: # crates/session-view/src/recall.rs # crates/session-view/src/timeline/row_height.rs
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
Eliminates per-frame heap allocations, deep JSON clones, and spurious
Trackedinvalidations acrosscrates/session-view,features/timeline-extras, andapps/desktop/src/shell/view/{session,composer}.rsduring 165 Hz streaming while preserving full animation framerate and zero visual changes.Live trace motivation (
opencode-desktop.exev0.0.0-dev-543)043341:meanAllocBytes = 782 KB/f(1,570 / 2,000viewframes without plugin surfaces averaged1,245 KB/f,4,085 allocs/f,p50 = 1,438 KB/f), Memo80.7%, Paint72.8%, spike17.3 MB(54,284allocs).043755:meanAllocBytes = 603 KB/f(viewframes without plugin surfaces averaged1,184 KB/f,5,994 allocs/f), Memo86.1%, Paint71.4%, spike16.2 MB(63,907allocs).044001:meanAllocBytes = 215 KB/f(viewframes without plugin surfaces averaged875 KB/f,4,016 allocs/f, spikes up to2.43 MB/f), Memo64.5%, Paint58.3%.What changed
1. Memoize
TurnDiff,TurnDivider, and settledCompactionrows + dropFileDiff.Infodeep clonescrates/session-view/src/tools/files.rs,tools/mod.rs,turn_diff.rs: Addedtools::shut_filesborrowing&[serde_json::Value]directly soturn_diff::viewno longer deep-clonesFileDiff.InfoJSON (d.to_vec()/.take(LIMIT).cloned()) into a syntheticserde_json::json!({ "files": files })object on every frame. Addedturn_diff::state_stamp(allocation-freeFxHasherover summary counts and visible file patches) andturn_diff::view_stateto reuse the fetchedState.crates/session-view/src/timeline/row_build.rs,compaction.rs: MemoizedRowContent::TurnDiff,RowContent::TurnDivider, and settled (status != Running)RowContent::Compaction(viacompaction::memo_stamp) so unchanged diffs, dividers, and expanded compaction Markdown summaries hitrune::memoacross streaming frames.2. Stop spurious 165 Hz
Trackedclock & drip invalidationscrates/session-view/src/jump.rs: Deferreds.clock()inLook::show/show_lookbehindimpl FnOnce() -> f64after theshown == was.shown && rise == was.riseearly return, stoppingover_scrollfrom readingTracked<f64>on every steady frame. Replacedentry(id.to_owned())with a read-firstget(id)lookup.crates/session-view/src/compaction.rs: Switched active compaction divider phase anchoring (quiet_view,light) from trackeds.clock()/s.now_ms()tos.working_state().poll_clock()ands.now_ms_untracked()(matchingworking::label_str). Loop animations remain at full 165 Hz in Rune's compositor.crates/session-view/src/line_reveal.rs: Moved internal bookkeeping (drip,poll,pending,seen) toRefCelland touchs.line_hold_mut()only when visible pacing/draining state actually changes, preventing sub-word cursor ticks and non-text transcript updates from invalidatingtimeline-fade. Eliminated per-framePartKey/sid/message_idclones on existingdripentries, reusedpendingcapacity in place, and replaced per-pollHashSet<(usize, usize)>with a pre-sizedVec.3. Eliminate per-frame row memo-key & lookup allocations
crates/session-view/src/timeline/row_build.rs:self.key.as_str()torune::memoinstead ofself.key.clone().prompt_metacalls inUser/Pendingrows (user_bubbleignoresmeta); removes turn-wide scans,ModelRefclones, andVec<(String, bool)>allocations twice per user row per frame (row_height::shape+row_build).TurnText: usecopied::stamp(s),group_hash::code_wrap_stamp(...), borrowedviewing.id.as_str(), andparts::has_reply_hover(...)(instead offormat!("reply-hover-{id}")).Turn::Group(collapsed): drop redundants.expanded().stamp("r-")(thought-only groups already hash their ownopen/shutting; non-thought groups only readr-when open/shutting), preventing thought toggles from invalidating unrelated collapsed groups.Turn::Group(open),Turn::Thought,Turn::Calls,Turn::Subagent,Turn::Question: reuse already-materializedStep/Vec<Step>insidememo_rowclosures instead of reconstructing twice on miss; inspect onlyat.first()for closedThoughtrows (zeroVec<Step>allocation); passNoneforgroup_keyon standaloneCallsrows.TurnFooter/TurnTail: useparts::reply_meta_stamp(borrowinga.model.as_ref()and hashing raw timestamps/TPS without formatting tooltip/duration strings or allocating aVec),copied::stamp(s), andcopied::is_copied_prefixed(s, "copy-", copy_id).crates/session-view/src/timeline/group_hash.rs: Replaced(u64, String)LRU lookup with borrowable(u64, &str)(with_entry, zerot.session.clone()per row per frame and zero.expect()), updatedfirst_id/last_idin place oninvalidate_from, replacedformat!("{:?}", n.kind)with zero-allochash_notice_kind, and switchedtools_auxtostamp_parts+copied::stamp.crates/session-view/src/timeline/turn_cache.rs: Replaced(u64, String, String)LRU lookups with borrowable(u64, &str, &str).crates/session-view/src/timeline/wrap.rs,fold.rs,disclosure.rs,copied.rs,recall.rs,timeline/mod.rs,timeline/parts.rs,timeline/row_height.rs:RowSpec::disclosurereturnsCow<'_, str>(zero alloc forc-*/fold).Disclosures::get_prefixed/get_parts,stamp_parts,any_shutting_parts,none_touched, and exportedfold::KEY_PREFIX.copied::stamp,copied::stamp_containing,copied::is_copied_prefixed, andcopied::is_empty(also used intools::cached_with).Recall::markschecksget(session)before allocatingsession.to_owned().parts::footer_textchecks the message's own trailing text part first and scans forwardt.messages[message + 1..]to short-circuit earlier turns immediately.timeline::turn_ofclears and reusesVec<usize>capacity on cache rebuild.4. Eliminate cache/helper cloning in
turns,sources_chip,timeline-extras, andshell/viewcrates/session-view/src/turns/codemode/cache.rs: Borrowable(&str, bool, bool)lookup key (zeroid.to_owned()on hit) and length + head/tail 32-byte attachment hashing instead of hashing fullArc<[u8]>image payloads.crates/session-view/src/turns/labels.rs: CheckSEEN_GROUPS.contains(key)before allocatingkey.to_owned().crates/session-view/src/sources_chip.rs: Returnimpl Iterator<Item = &str>fromresults, hash normalized URL parts without allocating inhash_assistant_sources, avoid callingpage(url)twice forwebfetch, and stop collectingsitespast 3.features/timeline-extras/src/todos.rs: StoreRc<[Todo]>inPLANcache and update cachedver/seen_verin place without reallocatingid/revertor deep-cloningVec<Todo>on every streaming poll/frame; deferid.to_owned()inpilluntil a pill renders; computepanel_widthonce inbuild_panel_content.features/timeline-extras/src/agent_rows/mod.rs: Replace intermediateVec<&String>allocation insteps_inwith a fixed[&str; KEEP]stack ring.apps/desktop/src/shell/view/session.rs: Pass borrowedOption<&str>for opening error and highlighted row intotimeline-faderegion inputs; constructpills()in a single pre-sizedVec<El>(zero alloc when empty).apps/desktop/src/shell/view/composer.rs: Replace per-stepvec![30.0, 0.0, 28.0]allocations infolds()with stack(sum, count)accumulators.Verification
git diff --check: cleanpwsh scripts/guardrails.ps1: 12/12 passed (all 24 touched.rsfiles<= 800lines; largest iscrates/session-view/src/timeline/row_build.rsat 797 lines; zero tests; zero new.cursor(...); zerostd::time::Instant/SystemTime::now)cargo clippy --no-deps -p opencode-feature-timeline-extras -- -D warnings: pass (0 warnings)cargo check -p session-view --examples: pass (0 warnings insession-view)cargo check -p opencode-desktop --no-default-features --features knobs: pass (0 warnings in touched files)cargo check -p opencode-web --target wasm32-unknown-unknown: pass (0 warnings in touched files)