fix: wrap EditDelta.new_lines in Arc to reduce memory from deep cloning#11623
Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
Draft
fix: wrap EditDelta.new_lines in Arc to reduce memory from deep cloning#11623warp-dev-github-integration[bot] wants to merge 1 commit into
warp-dev-github-integration[bot] wants to merge 1 commit into
Conversation
… changes Heap profiling from Sentry issue 7259255054 shows ~9.3 GB of cumulative allocations from Vec<StyledBufferBlock>::clone() in CodeEditorModel::handle_content_model_event. This happens because the EditDelta (containing the full styled buffer blocks) is deeply cloned every time it's propagated through the event system to the render state and delay rendering queues. Changes: - Wrap EditDelta.new_lines in Arc<Vec<StyledBufferBlock>> so cloning is O(1) reference counting instead of O(n) deep copy. - In layout_delta(), use Arc::try_unwrap() to cheaply unwrap the sole owner, falling back to clone only if shared. - Remove an unnecessary delta.clone() in DelayRendering::flush_render() where the delta was already owned by value. - Update all EditDelta construction sites to wrap with Arc::new(). Co-Authored-By: Oz <oz-agent@warp.dev>
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
Wraps
EditDelta.new_linesinArc<Vec<StyledBufferBlock>>to eliminate expensive deep cloning whenEditDeltais propagated through the event system.Problem
Heap profiling from Sentry issue 7259255054 shows ~9.3 GB of cumulative allocations from
Vec<StyledBufferBlock>::clone()inCodeEditorModel::handle_content_model_event. This is the #2 allocation site after the buffer's SumTree construction itself.When a file is loaded or its content changes, the
EditDelta(containing styled buffer blocks for the entire changed region) gets deep-cloned every time it passes through the event system:BufferEvent::ContentChangedto delay rendering queue (delta.clone())delta.clone()— this one was completely unnecessary since the delta was already owned)BufferEvent::ContentChangedto render state (delta.clone())For large files, each clone duplicates all the
StyledBufferBlockstrings, causing massive transient allocations.Changes
EditDelta.new_lines: Changed fromVec<StyledBufferBlock>toArc<Vec<StyledBufferBlock>>so cloning is O(1) reference counting instead of O(n) deep copylayout_delta(): UsesArc::try_unwrap()to cheaply unwrap when sole owner, falling back to clone only when sharedDelayRendering::flush_render(): Removed unnecessarydelta.clone()— the delta was already owned by value from consuming the vecEditDeltaconstruction sites to wrap withArc::new()Testing
cargo check -p warp_editorpassesArc<Vec<T>>auto-derefs toVec<T>for readsChangelog
CHANGELOG-IMPROVEMENT:
CHANGELOG-BUG-FIX:
CHANGELOG-IMAGE:
CHANGELOG-NEW-FEATURE:
Conversation: https://staging.warp.dev/conversation/57e99221-45e9-483b-bf35-ffee7c71c874
Run: https://oz.staging.warp.dev/runs/019e5841-4d9f-7185-969b-487b41700e56
This PR was generated with Oz.