Skip to content

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
masterfrom
fix/edit-delta-arc-new-lines-APP-4659
Open

fix: wrap EditDelta.new_lines in Arc to eliminate O(n) clone on file load (APP-4659)#12206
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/edit-delta-arc-new-lines-APP-4659

Conversation

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

@warp-dev-github-integration warp-dev-github-integration Bot commented Jun 4, 2026

Description

Wraps EditDelta.new_lines in Arc<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() in DelayRendering::flush_render.

Problem

When Buffer::replace_all() loads a large file, it creates an EditDelta whose new_lines field contains a Vec<StyledBufferBlock> for the entire file. Before this change, that Vec was deep-cloned at least once in the hot event-dispatch path:

  1. delta.clone() in CodeEditorModel::handle_content_model_event when pushing to delay_rendering.edits (required by borrow rules, but was O(n) expensive)
  2. delta.clone() in DelayRendering::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>>
  • Cloning an Arc is O(1), making event-dispatch clones essentially free
  • In layout_delta(), use Arc::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
  • Remove redundant .clone() in flush_render loop

Linked Issue

  • Related: APP-4659 (complementary fix; added comment with analysis)

Testing

  • I have manually tested my changes locally with ./script/run

Agent Mode

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

…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>
@cla-bot cla-bot Bot added the cla-signed label Jun 4, 2026
@lucieleblanc lucieleblanc marked this pull request as ready for review June 4, 2026 21:12
@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented Jun 4, 2026

@lucieleblanc

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 /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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