fix: bound code review base-content memory for large files (APP-4811)#13281
Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
Draft
fix: bound code review base-content memory for large files (APP-4811)#13281warp-dev-github-integration[bot] wants to merge 1 commit into
warp-dev-github-integration[bot] wants to merge 1 commit into
Conversation
Code review loaded the full base file content (`content_at_head`) into an editor buffer for every file with no size guard on local diffs, and built editors even for files too large to render. For reviews containing very large files this drove multi-GB heap usage (Sentry 7259255054): the dominant heap cost was per-file editor construction (SumTree<BufferText> rope + StyledBufferBlock computation) under CodeReviewView::build_view_state_for_file_diffs. - Enforce a per-file base-content budget (MAX_DIFF_SIZE) for local diffs, mirroring the limit already applied on the remote wire. Over-budget files are marked DiffSize::Unrenderable(FileTooLarge) and their base content is dropped, so the review shows a "file too large" placeholder instead of loading the whole file into an editor buffer. - Skip constructing an editor for DiffSize::Unrenderable files in the code review view; they render a size placeholder and never use an editor, so building one only wastes memory. 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
Fixes a multi-GB memory spike in the Code Review panel (Sentry 7259255054, heap ~11.2 GB). A symbolized heap profile showed 73% of the live heap funneling through
CodeReviewView::build_view_state_for_file_diffs, which builds a full editor stack (global buffer +SumTree<BufferText>rope +StyledBufferBlockcomputation + comment/rich-text editors) for the files in a diff.Two gaps amplified this for reviews containing very large files:
FileDiffAndContent.content_at_head(the entire file at the diff base) is loaded into an editor buffer.DiffSizeis computed from the patch size, not the base file, so a large file with a small diff is classifiedNormal, auto-expanded, and fully loaded. Remote sessions already withhold base content overMAX_DIFF_SIZEon the wire; local sessions had no equivalent cap.create_code_review_model_with_global_buffer/create_code_review_modelconstructed an editor (loading full content) even forDiffSize::Unrenderablefiles, whichrender_file_contentnever renders (it shows a size placeholder first).Changes
app/src/code_review/diff_state/local.rs: addenforce_base_content_budget, applied in both localFileDiffAndContentproducers (diff_state_against_head,file_diff_for_path). When base content exceedsMAX_DIFF_SIZE, drop it and mark the fileDiffSize::Unrenderable(FileTooLarge)— matching the documentedcontent_at_headcontract (over-budget files →None) and the existing remote budget.app/src/code_review/code_review_view.rs: skip editor construction forDiffSize::Unrenderablefiles in both create paths.Memory for a review with oversized files now scales with renderable content instead of loading whole files into editor buffers. This is a targeted mitigation; the broader fix (lazy per-file editor construction so memory scales with expanded files rather than total files) is tracked in APP-4811.
Linked Issue
APP-4811 (Linear). Related Sentry: 7259255054.
ready-to-specorready-to-implement.Testing
cargo check -p warp— passes.cargo clippy -p warp --tests -- -D warnings— passes clean.enforce_base_content_budget(small content preserved; over-budget content dropped + markedUnrenderable(FileTooLarge);Nonepassthrough). Tests compile underclippy --tests; the full test binary was not run to completion in the sandbox due to cold-build cost../script/runAgent Mode
Conversation: https://staging.warp.dev/conversation/efb723a8-ab2e-46f8-9eee-064effb466ba
Run: https://oz.staging.warp.dev/runs/019f1eb0-6535-7ee8-99c0-91ccb1fc5bbf
This PR was generated with Oz.