perf: batch SumTree BlockItem pushes to reduce memory in layout_pending_edit
Summary
Reduce peak memory usage in the editor's SumTreepush calls into extend.
Problem
Sentry issue 7259255054 (99 events, mac_stable_release) shows "Excessive memory usage detected" with ~11.8 GB of in-use heap memory. Heap profile analysis of the latest event reveals:
- ~6.7 GB (57%):
SumTree<BlockItem>::pushviaRenderState::layout_edit_delta— individual item pushes during content tree rebuilds - ~1.1 GB (9%):
SumTree<BlockItem>::push_tree_recursive— cascading Arc::make_mut clones during tree restructuring - ~1.8 GB (15%): Text layout operations (Glyph/CaretPosition allocation)
- ~1.3 GB (11%):
SumTree<BufferText>buffer operations
Root Cause
layout_pending_edit and reset_temporary_block push BlockItems into a new SumTree one at a time using SumTree::push(). Each push call:
- Creates a single-item leaf node wrapped in
Arc::new - Wraps it in an internal node via
from_child_trees - Calls
push_tree_recursive, which may triggerArc::make_mutclones on shared nodes from the prefix slice
For N items, this creates N separate push_tree_recursive calls, each potentially cloning shared tree nodes.
Fix
Replace individual push calls with batched extend in both layout_pending_edit and reset_temporary_block. SumTree::extend batches items into full leaf nodes (up to 2*TREE_BASE = 12 items each) before calling push_tree, reducing tree restructuring operations by ~12x.
For layout_pending_edit, the hidden ranges offset filter is pre-computed using a running extent tracker so items can be collected before batching.
Testing
cargo check -p warp_editor✅cargo clippy -p warp_editor -- -D warnings✅cargo fmt -p warp_editor -- --check✅
Sentry Alert
- Issue: https://sentry.io/organizations/warpdotdev/issues/7259255054/
- Event: 3ca558303a144a909c689b17ed77e2bd
- Environment: mac_stable_release (macOS 26.5.0)
- Frequency: 99 events since 2026-02-11
CHANGELOG-BUG-FIX: Fixed excessive memory usage during editor layout by batching SumTree operations, reducing tree node allocations by ~12x.
Conversation: https://staging.warp.dev/conversation/f62300bd-9dba-47f9-82d7-c6aed12b2be7 Run: https://oz.staging.warp.dev/runs/019e6e09-0ae4-7250-a318-b6bf33ee239d
This PR was generated with Oz.