Skip to content

fix: reduce memory usage from SessionContext clone and DirectoryFetcher#11626

Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
orchestrator/fix-memory-alert-1
Draft

fix: reduce memory usage from SessionContext clone and DirectoryFetcher#11626
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
orchestrator/fix-memory-alert-1

Conversation

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

Summary

Two targeted fixes for excessive memory usage identified via Sentry alert #7259255054.

Heap Profile Analysis (10 GB total footprint)

The heap profile from event 0e7bc8aa shows three major allocation categories:

  1. Vec<StyledBufferBlock>::clone — 5.66 GB (58.4%) in CodeEditorModel::handle_content_model_event. This is an architectural issue requiring EditDelta.new_lines to be wrapped in Arc — noted as follow-up work.
  2. SessionContext::clone (DashMap deep copy) — ~550 MB (5.4%) across display chip creation paths
  3. DirectoryFetcher::refetch_directory — ~930 MB (9.7%) from unbounded directory item vectors

Changes

1. Wrap SessionContext.cached_directory_entries in Arc<DashMap>

The SessionContext struct derives Clone, which deep-copies the DashMap<TypedPathBuf, Arc<Vec<EngineDirEntry>>> directory cache. This is called frequently from AgentInputFooter::create_display_chips and PromptDisplay::reset_chips. Wrapping in Arc makes clone O(1) while preserving interior mutability.

2. Cap DirectoryFetcher results to 1,000 items

Directories with very large numbers of entries (e.g. node_modules, .git/objects, build output) caused unbounded Vec<DirectoryItem> growth. Items are sorted first (directories → text files → binary files) so truncation preserves the most useful entries.

Follow-up needed

The dominant allocation (Vec<StyledBufferBlock>::clone at 5.66 GB) requires wrapping EditDelta.new_lines in Arc<Vec<StyledBufferBlock>> to avoid deep clones during content change events. This is a larger architectural change touching many files and tests.

Test Plan

  • cargo check
  • cargo clippy
  • cargo fmt

CHANGELOG-IMPROVEMENT:
CHANGELOG-BUG-FIX:
CHANGELOG-NEW-FEATURE:
CHANGELOG-IMAGE:


Conversation: https://staging.warp.dev/conversation/be54270e-a827-4115-a8f9-6049221a4fe3
Run: https://oz.staging.warp.dev/runs/019e58b0-c118-7a15-9f1a-0b2dbfd4a8c6
This PR was generated with Oz.

Two targeted fixes for excessive memory usage (Sentry #7259255054):

1. Wrap SessionContext.cached_directory_entries in Arc<DashMap> so that
   SessionContext::clone() is O(1) instead of deep-copying every cached
   directory listing. The DashMap already provides interior mutability,
   so shared ownership via Arc is safe. This eliminates ~550 MB of
   redundant allocations observed in the heap profile when display chips
   clone the session context.

2. Cap DirectoryFetcher results to 1,000 items after sorting. Directories
   with a very large number of entries (e.g. node_modules, .git/objects)
   were causing unbounded Vec<DirectoryItem> growth (~930 MB in the heap
   profile). The sort runs first so directories and text files are
   prioritised over binary files.

Co-Authored-By: Oz <oz-agent@warp.dev>
@cla-bot cla-bot Bot added the cla-signed label May 24, 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