fix: wrap EditDelta.new_lines in Arc to eliminate O(n) clone on file load (APP-4659)#12206
Open
warp-dev-github-integration[bot] wants to merge 1 commit into
Open
fix: wrap EditDelta.new_lines in Arc to eliminate O(n) clone on file load (APP-4659)#12206warp-dev-github-integration[bot] wants to merge 1 commit into
warp-dev-github-integration[bot] wants to merge 1 commit into
Conversation
…load (APP-4659) When a large file is opened, Buffer::replace_all() builds an EditDelta whose new_lines field contains Vec<StyledBufferBlock> for the **entire file**. That Vec was then cloned at least once before reaching the render thread: 1. delta.clone() in CodeEditorModel::handle_content_model_event when pushing to delay_rendering.edits (unavoidable given event dispatch by reference) 2. delta.clone() in DelayRendering::flush_render (unnecessary — the iterator yields owned values so no clone is needed) For a large file this cost 2.76 GB (24.3%) of the 11.07 GB sampled in the Sentry heap profile for issue 7259255054. Fix: change EditDelta.new_lines from Vec<StyledBufferBlock> to Arc<Vec<StyledBufferBlock>>. Cloning an Arc is O(1) (a reference-count bump), so the event-dispatch clone becomes essentially free. At layout time Arc::unwrap_or_clone() hands the Vec to layout_delta for free if this is the last reference (the common case), falling back to a single full copy only when multiple references exist (rare in practice). Also remove the redundant .clone() in flush_render; delta is already owned when iterating over self.edits. All 426 warp_editor unit tests continue to pass. Co-Authored-By: Oz <oz-agent@warp.dev>
Contributor
|
I'm starting a first review of this pull request. You can view the conversation on Warp. I completed the review and no human review was requested for this pull request. Comment Powered by Oz |
Contributor
There was a problem hiding this comment.
Overview
This PR wraps EditDelta.new_lines in Arc<Vec<StyledBufferBlock>> so EditDelta clones no longer deep-copy large styled block vectors, removes an unnecessary clone when flushing delayed rendering, and updates affected tests for the new field type.
Concerns
- No blocking correctness, security, or spec-drift concerns found in the attached diff. Visual evidence is not required because the change is an internal memory/performance optimization rather than a visual UI change.
Verdict
Found: 0 critical, 0 important, 0 suggestions
Approve
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
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.
Description
Wraps
EditDelta.new_linesinArc<Vec<StyledBufferBlock>>to eliminate an O(n) deep clone that occurs when a large file is opened in the code editor, and removes a redundant.clone()inDelayRendering::flush_render.Problem
When
Buffer::replace_all()loads a large file, it creates anEditDeltawhosenew_linesfield contains aVec<StyledBufferBlock>for the entire file. Before this change, that Vec was deep-cloned at least once in the hot event-dispatch path:delta.clone()inCodeEditorModel::handle_content_model_eventwhen pushing todelay_rendering.edits(required by borrow rules, but was O(n) expensive)delta.clone()inDelayRendering::flush_render(unnecessary — the iterator already yields owned values)For a large file, this caused 2.76 GB (24.3%) of the 11.07 GB sampled in a Sentry heap profile for issue 7259255054.
Fix
EditDelta.new_lines:Vec<StyledBufferBlock>→Arc<Vec<StyledBufferBlock>>Arcis O(1), making event-dispatch clones essentially freelayout_delta(), useArc::unwrap_or_clone()to hand ownership to the layout thread at zero cost when this is the last reference (the common case), falling back to a single clone only if other references exist.clone()inflush_renderloopLinked Issue
Testing
./script/runAgent Mode
CHANGELOG-NONE
Conversation: https://staging.warp.dev/conversation/0268f3c1-553b-4afe-b05f-5a9444c25977
Run: https://oz.staging.warp.dev/runs/019e937a-a647-71d2-83d5-d10ccf1d2b2e
This PR was generated with Oz.