fix: prevent multi-GiB memory spikes in editor for large files (APP-4519)#11397
Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
Draft
fix: prevent multi-GiB memory spikes in editor for large files (APP-4519)#11397warp-dev-github-integration[bot] wants to merge 1 commit into
warp-dev-github-integration[bot] wants to merge 1 commit into
Conversation
) Three defensive layers prevent the editor from consuming unbounded memory when loading very large files: 1. **File size guard (20 MB)**: FileModel and GlobalBufferModel reject files exceeding MAX_EDITOR_FILE_SIZE (20 MB) before reading content into the buffer. Applies to local files, remote buffers, and auto-reload paths. A user-friendly toast shows the file size and the limit. 2. **Lightweight layout (5 MiB)**: When an EditDelta's total content exceeds MAX_LAYOUT_BYTES, layout_text_block_lightweight creates empty TextFrames with correct font metrics instead of running expensive platform text layout (CoreText on macOS). This prevents the 19+ GiB SumTree<BlockItem> retention seen in the Sentry heap profile. 3. **Tree-sitter guard (1 MiB)**: Buffers exceeding MAX_SYNTAX_TREE_BUFFER_BYTES skip tree-sitter parsing entirely, avoiding multi-GiB heap spikes from grammars with expensive external scanners. Also removes an unnecessary .clone() on EditDelta in DelayRendering::flush_render. Sentry issue: https://warpdotdev.sentry.io/issues/7259255054/ Linear: APP-4519 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
Prevent multi-GiB memory spikes when loading very large files into the code editor. The Sentry memory alert (APP-4519) shows 24+ GiB heap usage dominated by
SumTree<BlockItem>::push(82.5%) andSumTree<BufferText>::append_str(13.7%) after a GlobalBufferModel file load.This PR implements three defensive layers:
File size guard (20 MB) —
FileModelandGlobalBufferModelreject files exceedingMAX_EDITOR_FILE_SIZEbefore reading content into the buffer. Applies to local files, remote buffers, and auto-reload paths. A user-friendly toast shows the file size and the limit.Lightweight layout (5 MiB threshold) — When an
EditDelta's total content exceedsMAX_LAYOUT_BYTES,layout_text_block_lightweightcreates emptyTextFrames with correct font metrics instead of running expensive platform text layout (CoreText on macOS). This prevents the 19+ GiBSumTree<BlockItem>retention seen in the Sentry heap profile.Tree-sitter guard (1 MiB) — Buffers exceeding
MAX_SYNTAX_TREE_BUFFER_BYTESskip tree-sitter parsing entirely, avoiding multi-GiB heap spikes from grammars with expensive external scanners.Also removes an unnecessary
.clone()onEditDeltainDelayRendering::flush_render.Files changed
crates/warp_util/src/file.rs— AddMAX_EDITOR_FILE_SIZEconstant andFileTooLargeerror variantcrates/warp_files/src/lib.rs— File size check before reading inopen(),read_content_for_file(), and auto-reloadapp/src/code/global_buffer_model.rs— Remote buffer size guard inapply_open_buffer_responseapp/src/code/view.rs— User-friendly toast for file-too-large errorsapp/src/ai/blocklist/action_model/execute.rs— HandleFileTooLargeerror variantcrates/editor/src/content/buffer.rs— Addbyte_len()andcontent_byte_len()helperscrates/editor/src/content/edit.rs— AddMAX_LAYOUT_BYTES,layout_text_block_lightweight, and lightweight layout dispatchcrates/syntax_tree/src/lib.rs— AddMAX_SYNTAX_TREE_BUFFER_BYTESguardapp/src/code/editor/model.rs— Remove unnecessary.clone()onEditDeltaLinked Issue
Testing
cargo fmt— passescargo clippy --workspace --all-targets --all-features --tests -- -D warnings— passesThis change addresses the root cause of the Sentry memory alert by preventing large file content from entering the editor pipeline
Warp Agent Mode - This PR was created via Warp's AI Agent Mode
Conversation: https://staging.warp.dev/conversation/84b4c4e8-93a6-4ca5-8773-4a7454f2224d
Run: https://oz.staging.warp.dev/runs/019e4450-ddfc-7a01-8ca0-2d3f07b81511
This PR was generated with Oz.