warp icon indicating copy to clipboard operation
warp copied to clipboard

perf: skip resize_storage for finished blocks on height-only terminal resizes

Open warp-agent-staging opened this issue 6 months ago • 0 comments

Description

Skip the expensive resize_storage push/pop cycle for finished (historical) terminal blocks when only the terminal height changes (columns unchanged).

Root Cause: Every terminal resize triggers BlockList::resize on ALL blocks with update_old_blocks=true. For each finished block, resize_storage materializes all visible rows from FlatStorage via pop_rows, which clones the Vec<Cell> data for every row. With many historical blocks in a long-running session, this creates 1.34GB of live cell data on every resize (observed in Sentry heap profile 7366781652).

Fix: For finished blocks where columns haven't changed, text layout is unchanged — no reflow is needed. The cursor is fixed and all row data remains accessible. We can safely skip the entire push/pop cycle with an early return.

Evidence from heap profile (8.14GB total):

  • FlatStorage::pop_rows → Vec<Row>::from_iter(Rc::unwrap_or_clone) = 1.26GB (15.5%)
  • Vec<Cell>::clone = 1.29GB (15.9%)
  • Both attributed to BlockList::resize → GridHandler::resize_storage triggered from TerminalView::after_terminal_view_layout

Fixes Sentry issue: https://sentry.io/organizations/warpdotdev/issues/7366781652/

Linked Issue

  • [x] The linked issue is labeled ready-to-spec or ready-to-implement.

Testing

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

All resize-related tests pass (20 tests):

test terminal::model::blockgrid::tests::test_resize_finished_block ... ok
test terminal::model::blockgrid::tests::test_resize_finished_softwrapped_block ... ok
test terminal::model::grid::grid_handler::tests::test_resize_finished_primary_with_full_grid_clear_behavior_uses_scrollback ... ok
test terminal::model::grid::grid_handler::secrets::tests::test_secret_redaction_secret_remains_after_resize ... ok
... 16 more resize tests pass

Agent Mode

  • [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode

Conversation: https://staging.warp.dev/conversation/8340d034-a99c-4eac-a5ec-8098de37a511 Run: https://oz.staging.warp.dev/runs/019e6c00-dd0d-7edd-80cd-4569d824e3e2

This PR was generated with Oz.

warp-agent-staging avatar May 28 '26 01:05 warp-agent-staging