Skip to content

fix: add 50MB file size limit to prevent memory spike in editor layout#12021

Closed
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/memory-large-file-size-limit
Closed

fix: add 50MB file size limit to prevent memory spike in editor layout#12021
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/memory-large-file-size-limit

Conversation

@warp-dev-github-integration
Copy link
Copy Markdown

Summary

Add a 50MB file size limit to the code editor's file loading path (FileModel::open and FileModel::read_content_for_file) to prevent excessive memory usage when opening very large files.

Root Cause

Sentry alert #7259255054 reports excessive memory usage (17.45GB sampled in heap profile). Analysis of the heap profile reveals:

  • SumTree<BlockItem>::push in RenderState::layout_edit_delta — 12.67GB (72.59% of total)
  • SumTree<BufferText>::append_str in populate_buffer_with_read_content — 2.08GB (11.94%)
  • SumTree<BlockItem>::push_tree / push_tree_recursive — 1.85GB (10.63%)

When a very large file is opened, the entire content is loaded into the buffer, and the editor's layout system creates BlockItem nodes for every line. Since each line generates multiple in-memory structures (text frames, selections, caret positions, etc.), a file that is large on disk can consume 5-10x more memory once fully laid out.

Changes

  1. crates/warp_util/src/file.rs: Added FileTooLarge { size_bytes, limit_bytes } variant to FileLoadError
  2. crates/warp_files/src/lib.rs: Added MAX_EDITOR_FILE_SIZE (50MB) constant and check_file_size helper. Updated FileModel::open and read_content_for_file to check file size before reading.
  3. app/src/ai/blocklist/action_model/execute.rs: Handle new FileTooLarge variant in exhaustive match

Test Plan

  • cargo check -p warp_files -p warp_util passes
  • Files under 50MB continue to open normally
  • Files over 50MB will trigger FileLoadError::FileTooLarge, surfacing through the existing FailedToLoad event path

Follow-up

  • Consider adding a user-visible message when a file is rejected for being too large
  • Long-term: implement virtual/lazy rendering so the layout system only materializes visible lines

Conversation: https://staging.warp.dev/conversation/eed39afb-2a7e-47ef-b94b-b15dcfc91cce
Run: https://oz.staging.warp.dev/runs/019e8484-219d-70b4-9dc3-af3b4d5d9c1c

This PR was generated with Oz.

When a very large file is opened in the code editor, the buffer loading
and layout systems can consume excessive memory. The editor's layout
system (SumTree<BlockItem>) creates multiple in-memory structures per
line, so a file that is large on disk can consume 5-10x more memory
once fully laid out.

This commit adds a 50MB file size limit check in FileModel::open and
FileModel::read_content_for_file. Files exceeding this threshold are
rejected with FileLoadError::FileTooLarge instead of being loaded into
memory and laid out.

Sentry issue: https://sentry.io/organizations/warpdotdev/issues/7259255054/
Heap profile evidence: SumTree<BlockItem>::push consumed 12.67GB (72.59%
of 17.45GB total) during RenderState::layout_edit_delta.

Co-Authored-By: Oz <oz-agent@warp.dev>
@kevinchevalier
Copy link
Copy Markdown
Contributor

Closing as duplicate of #12125 — both add a 50 MB FileTooLarge file size guard in FileModel::open. Keeping the newest PR.

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.

2 participants