fix: wrap EditDelta.new_lines in Arc to avoid expensive deep clones#11625
Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
Draft
fix: wrap EditDelta.new_lines in Arc to avoid expensive deep clones#11625warp-dev-github-integration[bot] wants to merge 1 commit into
warp-dev-github-integration[bot] wants to merge 1 commit into
Conversation
When content changes are emitted via BufferEvent::ContentChanged, the EditDelta (which includes all styled buffer blocks for the changed range) is cloned by multiple subscribers. For large files or full-buffer invalidations, this deep-copies all String data in StyledBufferRun, leading to massive memory usage (5.80GB / 61% of 9.46GB observed in heap profiles from Sentry issue 7259255054). This change wraps the new_lines field in Arc<Vec<StyledBufferBlock>> so that cloning an EditDelta performs a cheap reference count increment instead of a deep copy. The layout_delta method uses Arc::try_unwrap to avoid an extra clone when consuming the delta. 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.
Description
Wrap
EditDelta.new_linesinArc<Vec<StyledBufferBlock>>to avoid expensive deep clones when the delta is shared across multiple subscribers (e.g.CodeEditorModel→RenderState).Root Cause
When content changes are emitted via
BufferEvent::ContentChanged, theEditDelta(which includes all styled buffer blocks for the changed range) is cloned by each subscriber. For large files or full-buffer invalidations likeinvalidate_layout, this deep-copies allStringdata in everyStyledBufferRun, leading to massive memory usage.Heap profile from Sentry issue 7259255054 (9.46GB total in-use):
Vec<StyledBufferBlock>::cloneinCodeEditorModel::handle_content_model_eventDirectoryFetcher::fetch_files_async(separate issue)rebuild_layout_and_refresh_difflayout invalidationFix
EditDelta.new_linestype fromVec<StyledBufferBlock>toArc<Vec<StyledBufferBlock>>EditDelta::new()constructor that wraps in Arcbuffer.rsandcore.rslayout_deltausesArc::try_unwrapto avoid cloning when this is the last referenceLinked Issue
Testing
cargo check --workspacepassescargo clippy -p warp_editor --all-targetspasses with no warningscargo check -p warp_editor --testspassesAgent Mode
Conversation: https://staging.warp.dev/conversation/dbd6a0a5-bebd-443f-982c-5cb279fed4e7
Run: https://oz.staging.warp.dev/runs/019e5894-9699-7f31-8efb-1eb904aa942b
This PR was generated with Oz.