Skip to content

fix: defer code review editor creation for collapsed files (APP-4518)#11381

Closed
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/deferred-code-review-editors-app-4518
Closed

fix: defer code review editor creation for collapsed files (APP-4518)#11381
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/deferred-code-review-editors-app-4518

Conversation

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

Description

Fix memory spike in code review diff rendering by deferring editor creation for collapsed files.

Root cause: CodeReviewView::build_view_state_for_file_diffs eagerly created full editor view stacks (LocalCodeEditorViewCodeEditorViewCommentEditorGlobalBufferModel) for every file in the diff set, including collapsed files (binary, autogenerated, large diffs). The heap profile shows this path allocating 4–8 GiB on large diff sets.

Fix:

  1. Added deferred_content_at_head field to FileState to retain base content for collapsed files without creating editor stacks.
  2. In build_view_state_for_file_diffs, skip editor creation when is_expanded == false; store content_at_head for later.
  3. Added ensure_editor_for_file(), which lazily creates the editor when the user first expands/selects a collapsed file.
  4. Hooked ensure_editor_for_file() into ToggleFileExpanded and FileSelected handlers.
  5. Fixed FileInvalidationError::is_transient() to return false for permanent git failures (paths containing /null from submodule/tree entries) to avoid wasteful retries.

Secondary finding: The /null path failures in breadcrumbs (e.g. Could not access '.../step/04.1.z/null') are from git encountering tree objects where it expects blobs. These are correctly treated as binary (no editor created), but the retry queue was treating the failures as transient and retrying 3 times unnecessarily.

This event is the same variant as APP-4518, not a new variant. PRs #11285 and #11281 target the same root cause but remain unmerged; this PR is an independent implementation.

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

  • cargo check --package warp --tests passes ✅
  • cargo fmt -- --check passes ✅
  • cargo clippy -p warp --all-targets -- -D warnings passes ✅
  • I have manually tested my changes locally with ./script/run

Existing unit tests in code_review_view_tests.rs updated to include the new deferred_content_at_head field.

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

CHANGELOG-BUG-FIX: Fixed memory spike (~4-8 GiB) when opening the code review panel with large diffs by deferring editor construction for collapsed files

Conversation: https://staging.warp.dev/conversation/bc5666e2-7409-47a9-843d-9413922dfc07
Run: https://oz.staging.warp.dev/runs/019e4375-3d99-762f-946f-3719f842f2d4

This PR was generated with Oz.

Root cause: build_view_state_for_file_diffs eagerly created full editor
view stacks (LocalCodeEditorView → CodeEditorView → CommentEditor →
GlobalBufferModel) for every file in the diff set, including collapsed
files (binary, autogenerated, large diffs). For large PRs this allocated
multi-GB of styled buffer data that was never rendered.

Fix:
1. Added deferred_content_at_head field to FileState to retain the base
   content for collapsed files without creating editor view stacks.
2. In build_view_state_for_file_diffs, skip editor creation for files
   where is_expanded == false; store content_at_head for later.
3. Added ensure_editor_for_file() which lazily creates the editor when
   the user first expands/selects a collapsed file.
4. Hooked ensure_editor_for_file() into ToggleFileExpanded and
   FileSelected action handlers.
5. Fixed FileInvalidationError::is_transient() to return false for
   permanent git failures (e.g. paths containing /null from submodule
   or tree entries) to avoid wasteful retries.

Expected memory reduction: For a PR with N collapsed files, this avoids
allocating ~50-100MB per file upfront. Based on the Sentry heap profile,
this addresses the ~4-8 GiB from eager editor/buffer construction.

Linked issues:
- Sentry: https://warpdotdev.sentry.io/issues/7259255054/
- Linear: 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.

2 participants