fix: lazy editor instantiation for collapsed diff files (APP-4518)#11285
Closed
warp-dev-github-integration[bot] wants to merge 1 commit into
Closed
fix: lazy editor instantiation for collapsed diff files (APP-4518)#11285warp-dev-github-integration[bot] wants to merge 1 commit into
warp-dev-github-integration[bot] wants to merge 1 commit into
Conversation
Defer creation of the expensive editor view stack (LocalCodeEditorView → CodeEditorView → CommentEditor → RichTextEditorView → EditorView → EditorModel) for diff files that start collapsed in the code review panel. Previously, build_view_state_for_file_diffs eagerly created a full editor stack for every file in the diff set — including binary files, autogenerated files, and large diffs that auto-collapse. The heap profile from Sentry event 877fe4a5 shows this path allocating ~24 GB, with CommentEditor::new alone responsible for ~15.5 GB (53.6% of a 28.9 GB heap). The fix: - Add a content_at_head field to FileState to retain the base content needed for deferred editor creation. - In build_view_state_for_file_diffs, skip editor creation for files where is_expanded is false; store the content_at_head for later. - Add ensure_editor_for_file(), which lazily creates the editor on first expand. - Call ensure_editor_for_file() from ToggleFileExpanded and FileSelected handlers so editors are created on-demand when the user actually opens a file. This reduces the upfront allocation proportionally to the fraction of collapsed files in the diff. For diffs with many autogenerated or large files, this can eliminate the majority of the 24 GB allocation spike. Sentry: https://warpdotdev.sentry.io/issues/7259255054/ Linear: APP-4518 Co-Authored-By: Oz <oz-agent@warp.dev>
7 tasks
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
Fix memory spike in code review diff rendering by deferring editor creation for collapsed files.
Root cause:
CodeReviewView::build_view_state_for_file_diffseagerly created full editor view stacks (LocalCodeEditorView→CodeEditorView→CommentEditor→RichTextEditorView→EditorView→EditorModel) for every file in the diff set, regardless of whether the file starts collapsed. The heap profile shows this path allocating ~24 GB on a single diff load, withCommentEditor::newalone responsible for ~15.5 GB (53.6% of the 28.9 GB heap).Fix: Implement lazy editor instantiation:
content_at_head: Option<String>toFileStateto retain the base content needed for deferred editor creation.build_view_state_for_file_diffs, skip editor creation for files whereis_expanded == false; storecontent_at_headfor later.ensure_editor_for_file(), which lazily creates the editor when a file is first expanded.ensure_editor_for_file()intoToggleFileExpandedandFileSelectedhandlers.Files that auto-collapse (binary, autogenerated, large diffs) no longer allocate editor stacks upfront. Editor creation is deferred until the user explicitly expands the file.
Linked Issue
Testing
cargo check --package warp --testspassescargo fmt -- --checkpasses./script/runAgent Mode
CHANGELOG-BUG-FIX: Fixed memory spike when opening the code review panel with large diffs by deferring editor creation for collapsed files
Conversation: https://staging.warp.dev/conversation/7db7db17-c650-40a9-bbc5-bb0664664588
Run: https://oz.staging.warp.dev/runs/019e4067-9f22-774d-a362-a3116b04a8a8
This PR was generated with Oz.