fix: reduce table layout memory by Arc-sharing, reusing TextFrames, and adding row limit (APP-4687)#11834
Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
Draft
Conversation
…nd adding row limit (APP-4687) Three optimizations to reduce memory spikes during markdown table rendering in layout_table_block: 1. Wrap TableBlockCache fields (table, cell_offset_maps, offset_map) in Arc and share via Arc::clone instead of deep-cloning on every layout pass. 2. Retain the measurement-pass TextFrame from measure_table_cells and reuse it in the final pass when the cell's natural width fits within the computed column width without wrapping, avoiding redundant text layout. 3. Add MAX_TABLE_BODY_ROWS (500) limit to truncate very large tables during layout, preventing unbounded memory growth. Full source text is preserved in the buffer for copy/paste and editing. Co-Authored-By: Oz <oz-agent@warp.dev>
97fe06f to
aa50f1b
Compare
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
Reduces memory spikes during markdown table rendering in
layout_table_blockwith three targeted optimizations.Root cause (from heap profile): Sentry issue 7259255054 showed 8.73 GB sampled heap, with 81% from
EditDelta::layout_deltaon rayon threads. The dominant allocation sites were:layout_text→line_from_ct_linecreating Line/CaretPosition/Glyph objects: 2.87 GB (33%)TableBlockCache::build: 1.23 GB (14%)Three fixes:
Arc-wrap
TableBlockCachefields —FormattedTable,cell_offset_maps, andoffset_mapare now wrapped inArcand shared viaArc::cloneinstead of deep-cloned on every layout pass. This saves ~0.55 GB for large tables.Reuse measurement-pass TextFrames —
measure_table_cellsnow retains the TextFrame from the measurement pass (unconstrained width layout). In the final pass, cells whose natural width fits within the computed column width reuse the measurement TextFrame instead of running a second layout. This avoids redundant text layout for cells that don't need re-wrapping.Add
MAX_TABLE_BODY_ROWSlimit (500) — Very large tables are truncated during layout to prevent unbounded memory growth. The full source text is preserved in the buffer so copy/paste and editing are unaffected.Complementary to: PR #12312 (APP-4686) which bounds rayon parallelism. This PR reduces per-task memory for table blocks specifically.
Linear: APP-4687
Linked Issue
ready-to-specorready-to-implement.Testing
./script/runAutomated:
cargo check,cargo clippy -p warp_editor --all-targets -- -D warnings, and./script/formatall pass.Agent Mode
Conversation: https://staging.warp.dev/conversation/488199a4-db3c-4bfe-a4cc-6be9ec1a0336
Run: https://oz.staging.warp.dev/runs/019e9fed-7b13-715f-a98e-1c10b52ac053
This PR was generated with Oz.