Skip to content

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
masterfrom
oz/mem-app-4811-code-review-editor-budget
Draft

fix: bound code review base-content memory for large files (APP-4811)#13281
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
oz/mem-app-4811-code-review-editor-budget

Conversation

@warp-dev-github-integration

Copy link
Copy Markdown
Contributor

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 + StyledBufferBlock computation + comment/rich-text editors) for the files in a diff.

Two gaps amplified this for reviews containing very large files:

  1. No base-content size guard on local diffs. FileDiffAndContent.content_at_head (the entire file at the diff base) is loaded into an editor buffer. DiffSize is computed from the patch size, not the base file, so a large file with a small diff is classified Normal, auto-expanded, and fully loaded. Remote sessions already withhold base content over MAX_DIFF_SIZE on the wire; local sessions had no equivalent cap.
  2. Editors were built for unrenderable files. create_code_review_model_with_global_buffer / create_code_review_model constructed an editor (loading full content) even for DiffSize::Unrenderable files, which render_file_content never renders (it shows a size placeholder first).

Changes

  • app/src/code_review/diff_state/local.rs: add enforce_base_content_budget, applied in both local FileDiffAndContent producers (diff_state_against_head, file_diff_for_path). When base content exceeds MAX_DIFF_SIZE, drop it and mark the file DiffSize::Unrenderable(FileTooLarge) — matching the documented content_at_head contract (over-budget files → None) and the existing remote budget.
  • app/src/code_review/code_review_view.rs: skip editor construction for DiffSize::Unrenderable files 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.

  • The linked issue is labeled ready-to-spec or ready-to-implement.

Testing

  • cargo check -p warp — passes.
  • cargo clippy -p warp --tests -- -D warnings — passes clean.
  • Added unit tests for enforce_base_content_budget (small content preserved; over-budget content dropped + marked Unrenderable(FileTooLarge); None passthrough). Tests compile under clippy --tests; the full test binary was not run to completion in the sandbox due to cold-build cost.
  • 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/efb723a8-ab2e-46f8-9eee-064effb466ba
Run: https://oz.staging.warp.dev/runs/019f1eb0-6535-7ee8-99c0-91ccb1fc5bbf

This PR was generated with Oz.

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>
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