Skip to content

fix: defer code review editor creation for collapsed files (memory fix)#12216

Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/lazy-code-review-editor-creation
Draft

fix: defer code review editor creation for collapsed files (memory fix)#12216
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/lazy-code-review-editor-creation

Conversation

@warp-dev-github-integration

Copy link
Copy Markdown

Description

Defer code review editor creation for collapsed file diffs to significantly reduce memory usage.

When CodeReviewView loads diffs, it previously created the full editor view hierarchy (LocalCodeEditorViewCodeEditorViewCommentEditorRichTextEditorViewEditorViewEditorModel) for every file diff, even ones that start collapsed.

A Sentry heap profile (7.73GB) showed this eager creation was responsible for ~3GB+ (38%) of allocations:

  • build_view_state_for_file_diffs → 3045MB
  • Menu SubMenu rendering across editor views → ~1.8GB
  • Each editor creates deeply nested view + model + buffer hierarchies

Fix: Skip editor creation for collapsed files. Store content_at_head in FileState and lazily create the editor when the file is first expanded via ToggleFileExpanded or FileSelected.

Files that are auto-expanded (normal-sized, non-binary, non-autogenerated) still get their editors created eagerly, so there's no UX regression for the common case.

Linked Issue

Testing

  • Verified cargo check and cargo clippy pass with no warnings

  • The change is additive — collapsed files get editor_state: None instead of a fully constructed editor; expanded files behave identically to before

  • ensure_editor_for_file re-uses the same create_code_review_model_with_global_buffer / create_code_review_model codepaths as before

  • 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/ee03a0a7-8420-4a23-a37b-f6509e5081c5
Run: https://oz.staging.warp.dev/runs/019e942d-f916-79d4-81a4-b4aee3279cd3
This PR was generated with Oz.

When CodeReviewView loads diffs, it previously created the full editor
view hierarchy (LocalCodeEditorView → CodeEditorView → CommentEditor →
RichTextEditorView → EditorView → EditorModel) for every file diff,
even ones that start collapsed.

Each editor hierarchy allocates substantial memory for view state,
menu items, buffers, and layout data. For reviews with many files,
this eager creation was responsible for ~3GB+ of allocations (38% of
a 7.73GB heap profile).

This change defers editor creation for collapsed files:
- build_view_state_for_file_diffs now skips editor creation when
  is_expanded is false, storing content_at_head for later use
- A new ensure_editor_for_file method lazily creates the editor
  when a file is first expanded
- ToggleFileExpanded and FileSelected handlers call
  ensure_editor_for_file before rendering the expanded content

Files that are auto-expanded (normal-sized, non-binary, non-autogenerated)
still get their editors created eagerly so there's no UX regression for
the common case.

Closes APP-4564

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