Skip to content

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
masterfrom
oz/memory-fix-7259255054
Draft

fix: reduce table layout memory by Arc-sharing, reusing TextFrames, and adding row limit (APP-4687)#11834
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
oz/memory-fix-7259255054

Conversation

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

@warp-dev-github-integration warp-dev-github-integration Bot commented May 28, 2026

Description

Reduces memory spikes during markdown table rendering in layout_table_block with three targeted optimizations.

Root cause (from heap profile): Sentry issue 7259255054 showed 8.73 GB sampled heap, with 81% from EditDelta::layout_delta on rayon threads. The dominant allocation sites were:

  • layout_textline_from_ct_line creating Line/CaretPosition/Glyph objects: 2.87 GB (33%)
  • TableBlockCache::build: 1.23 GB (14%)
  • Table data cloning (FormattedTextFragment, TableCellOffsetMap): ~0.55 GB
  • Caret positions: 0.83 GB (10%)

Three fixes:

  1. Arc-wrap TableBlockCache fieldsFormattedTable, cell_offset_maps, and offset_map are now wrapped in Arc and shared via Arc::clone instead of deep-cloned on every layout pass. This saves ~0.55 GB for large tables.

  2. Reuse measurement-pass TextFramesmeasure_table_cells now 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.

  3. Add MAX_TABLE_BODY_ROWS limit (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

  • The linked issue is labeled ready-to-spec or ready-to-implement.
  • Where appropriate, screenshots or a short video of the implementation are included below (especially for user-visible or UI changes).

Testing

  • I have manually tested my changes locally with ./script/run

Automated: cargo check, cargo clippy -p warp_editor --all-targets -- -D warnings, and ./script/format all pass.

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI 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.

@cla-bot cla-bot Bot added the cla-signed label May 28, 2026
…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>
@warp-dev-github-integration warp-dev-github-integration Bot changed the title perf: wrap EditDelta.new_lines in Arc to eliminate O(n) clones on large files (APP) fix: reduce table layout memory by Arc-sharing, reusing TextFrames, and adding row limit (APP-4687) Jun 7, 2026
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