Skip to content

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
masterfrom
fix/arc-wrap-edit-delta-new-lines
Draft

fix: wrap EditDelta.new_lines in Arc to avoid expensive deep clones#11625
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/arc-wrap-edit-delta-new-lines

Conversation

@warp-dev-github-integration
Copy link
Copy Markdown

Description

Wrap EditDelta.new_lines in Arc<Vec<StyledBufferBlock>> to avoid expensive deep clones when the delta is shared across multiple subscribers (e.g. CodeEditorModelRenderState).

Root Cause

When content changes are emitted via BufferEvent::ContentChanged, the EditDelta (which includes all styled buffer blocks for the changed range) is cloned by each subscriber. For large files or full-buffer invalidations like invalidate_layout, this deep-copies all String data in every StyledBufferRun, leading to massive memory usage.

Heap profile from Sentry issue 7259255054 (9.46GB total in-use):

  • 5.80GB (61%): Vec<StyledBufferBlock>::clone in CodeEditorModel::handle_content_model_event
  • 0.91GB (10%): DirectoryFetcher::fetch_files_async (separate issue)
  • 0.86GB (9%): rebuild_layout_and_refresh_diff layout invalidation
  • 0.76GB (8%): Buffer text editing operations

Fix

  • Changed EditDelta.new_lines type from Vec<StyledBufferBlock> to Arc<Vec<StyledBufferBlock>>
  • Added EditDelta::new() constructor that wraps in Arc
  • Updated all construction sites in buffer.rs and core.rs
  • layout_delta uses Arc::try_unwrap to avoid cloning when this is the last reference
  • Test assertions dereference the Arc for comparison

Linked Issue

Testing

  • cargo check --workspace passes
  • cargo clippy -p warp_editor --all-targets passes with no warnings
  • cargo check -p warp_editor --tests passes

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent 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.

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>
@cla-bot cla-bot Bot added the cla-signed label May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant