warp icon indicating copy to clipboard operation
warp copied to clipboard

fix: add skip_caret_positions option to reduce text layout memory

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

Summary

Add a skip_caret_positions field to LineStyle that enables callers to skip computing caret positions during text layout. This provides infrastructure for reducing memory usage in display-only text rendering.

Context

Sentry memory alert analysis (issue 7259255054) showed 11.6 GB of live memory during a 20+ hour Agent Mode session on macOS stable. Heap profile breakdown:

  • ~3.5 GB (30%): CaretPosition vectors from caret_positions_for_line — eagerly computed for every text line, including display-only UI text
  • ~2.8 GB (24.4%): tree-sitter parsing during AgentManagementView creation
  • ~1.4 GB: Editor content/rendering (SumTree, syntax highlights)

Caret positions (cursor/selection snap points) are only needed for interactive text. Display-only text (menus, labels, banners, formatted text) never uses them but still pays the memory cost.

Changes

  • Add skip_caret_positions: bool to LineStyle (default false — backwards compatible)
  • Modify line_from_ct_line on macOS to skip caret_positions_for_line when flag is set
  • Update Line::first_index() and Line::last_index() to fall back to glyph data when caret positions are empty

Follow-ups

  • Enable skip_caret_positions: true for specific display-only callers (formatted text elements, shimmering text, menu items) to realize the memory savings
  • Investigate tree-sitter memory growth during long Agent Mode sessions

Conversation: https://staging.warp.dev/conversation/9e759d18-e877-4fec-b797-9cfe08836188 Run: https://oz.staging.warp.dev/runs/019e710a-89c8-7a02-bc7c-adf502685bf9 This PR was generated with Oz.

warp-agent-staging avatar May 29 '26 00:05 warp-agent-staging