fix: add 50MB file size guard to prevent excessive memory usage when opening large files
Summary
Add a 50 MB file size guard to FileModel::open to prevent excessive memory usage when opening very large files in the editor.
Problem
When a very large file (hundreds of MB+) is opened in the editor, the entire content is loaded into a SumTree<BufferText> buffer via Buffer::replace_all, then cloned into Vec<StyledBufferBlock> for rendering, then layout is invalidated rebuilding all styled blocks, and diffs are computed — all without any size guard. A single large file can cascade into 15+ GB of in-use memory.
This was identified from a Sentry memory alert (issue 7259255054) with 18.6 GB resident memory. Heap profile breakdown:
Buffer::replace_allviapopulate_buffer_with_read_content: 7.6 GB (47%)StyledBufferBlockcloning inhandle_content_model_event: 2.8 GB (17%)- Layout invalidation in
rebuild_layout_and_refresh_diff: 2.5 GB (15%) LocalDiffStateModel::parse_diff_hunks: 2.3 GB (15%)DiffModel::compute_diff: 0.4 GB (2%)
Changes
FileLoadError::FileTooLarge— New error variant inwarp_util::filethat carries the file size and the limit.- Pre-read size check in
FileModel::open— Before reading the file content into aString, we stat the file viaasync_fs::metadataand reject files exceeding 50 MB withFileLoadError::FileTooLarge. This prevents the entire allocation chain from executing.
The existing FailedToLoad error path in the UI already handles load failures gracefully (the editor shows an empty/new-file state), so this change integrates cleanly.
Testing
cargo check --package warp_files --package warp_util✅cargo clippy --package warp_files --package warp_util -- -D warnings✅cargo fmt✅
CHANGELOG-BUG-FIX: Fixed excessive memory usage (15+ GB) when opening very large files in the editor by adding a 50 MB file size limit.
Conversation: https://staging.warp.dev/conversation/27cd8261-18ad-4000-9607-03e08b76ab05 Run: https://oz.staging.warp.dev/runs/019e6d8e-6398-7d2a-92aa-bb52ef63c0f7 This PR was generated with Oz.