Skip to content

fix: defer code review editor construction for collapsed file diffs (APP-4518)#11250

Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/memory-spike-lazy-diff-editor-construction
Draft

fix: defer code review editor construction for collapsed file diffs (APP-4518)#11250
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/memory-spike-lazy-diff-editor-construction

Conversation

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

Description

Fix a memory spike in code review diff rendering (Sentry issue #7259255054) where CodeReviewView::build_view_state_for_file_diffs eagerly constructs editor state (GlobalBufferModel, CodeEditorView, styled buffer blocks, full layout computation) for every file diff — including collapsed files that are never rendered.

Root cause: Editor and global-buffer construction happened unconditionally for all non-binary files. Only afterward was the expansion state checked. For large PRs with many files, the majority are collapsed (binary, autogenerated, or large), yet each still materialized ~50-100MB of styled buffer data, pushing total in-use heap to ~9GB.

Fix: Defer editor construction for collapsed files. Only the lightweight content_at_head string is stored; the full editor is created lazily when the user expands the file via ensure_editor_for_file().

Impact from heap profile:

  • CodeEditorView constructors: 2.52GB → 0 for collapsed files
  • Buffer::invalidate_layout_internal: 2.00GB → 0 for collapsed files
  • GlobalBufferModel::populate_buffer_with_read_content: 0.76GB → 0 for collapsed files

Linked Issue

  • APP-4518

  • Sentry #7259255054

  • The linked issue is labeled ready-to-spec or ready-to-implement.

  • Where appropriate, screenshots or a short video of the implementation are included below (especially for user-visible or UI changes).

Testing

  • Verified the change compiles cleanly with cargo clippy -p warp --all-targets -- -D warnings

  • Ran cargo fmt with no formatting issues

  • Existing unit tests in code_review_view_tests.rs pass (updated test to include new content_at_head field)

  • The change is behavioral: collapsed files now start without editors, and editors are created on-demand when expanded. All existing expansion/selection/comment code paths that reference editor_state already handle None gracefully.

  • 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

Conversation: https://staging.warp.dev/conversation/8cd0fec7-59be-4a0c-88c9-d8f2a02cac88
Run: https://oz.staging.warp.dev/runs/019e3d9b-6ab9-7405-8e98-43f8c4aedb46
This PR was generated with Oz.

Fixes a memory spike (~9GB heap, Sentry issue 7259255054) caused by
CodeReviewView::build_view_state_for_file_diffs eagerly constructing
editor state (GlobalBufferModel, CodeEditorView, layout computation)
for every file diff including collapsed ones that are never rendered.

Changes:
- Check should_auto_expand_file BEFORE creating editor state. Collapsed
  files now store only content_at_head (a plain String) instead of a
  full editor view with styled buffer blocks.
- Add ensure_editor_for_file() for lazy on-demand editor creation when
  the user expands a previously-collapsed file.
- Wire lazy creation into ToggleFileExpanded and FileSelected handlers.
- Keep content_at_head fresh in the single-file update path so lazy
  creation uses up-to-date content.

For a PR with N collapsed files this avoids ~4.5GB of allocations from
CodeEditorView constructors (2.52GB) and layout invalidation (2.00GB)
that were shown in the heap profile.

APP-4518

Co-Authored-By: Oz <oz-agent@warp.dev>
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