fix: defer code review editor creation for collapsed files (memory fix)#12216
Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
Draft
fix: defer code review editor creation for collapsed files (memory fix)#12216warp-dev-github-integration[bot] wants to merge 1 commit into
warp-dev-github-integration[bot] wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Defer code review editor creation for collapsed file diffs to significantly reduce memory usage.
When
CodeReviewViewloads diffs, it previously created the full editor view hierarchy (LocalCodeEditorView→CodeEditorView→CommentEditor→RichTextEditorView→EditorView→EditorModel) 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→ 3045MBSubMenurendering across editor views → ~1.8GBFix: Skip editor creation for collapsed files. Store
content_at_headinFileStateand lazily create the editor when the file is first expanded viaToggleFileExpandedorFileSelected.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
APP-4564: Limit number of code editor views rendered after loading diffs in the Code Review Panel
Sentry: Excessive memory usage detected (285 events)
The linked issue is labeled
ready-to-specorready-to-implement.Where appropriate, screenshots or a short video of the implementation are included below (especially for user-visible or UI changes).
Testing
Verified
cargo checkandcargo clippypass with no warningsThe change is additive — collapsed files get
editor_state: Noneinstead of a fully constructed editor; expanded files behave identically to beforeensure_editor_for_filere-uses the samecreate_code_review_model_with_global_buffer/create_code_review_modelcodepaths as beforeI have manually tested my changes locally with
./script/runAgent 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.