Skip to content

fix: reduce memory spike from DirectoryFetcher and SessionContext clone#11606

Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/memory-directory-fetcher-session-context-clone
Draft

fix: reduce memory spike from DirectoryFetcher and SessionContext clone#11606
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/memory-directory-fetcher-session-context-clone

Conversation

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

Description

Fix excessive memory usage (9.06GB) caused by two issues in the context chips directory fetcher and session context path completion cache:

  1. SessionContext::clone() deep-copies the entire DashMap cache (~2.36GB): The cached_directory_entries field is a DashMap<TypedPathBuf, Arc<Vec<EngineDirEntry>>>. Since SessionContext derives Clone, every clone deep-copies all keys and values. This happens on every refetch_directory call and whenever context chips are reset. Wrapping the DashMap in Arc makes cloning O(1) while sharing the same underlying cache.

  2. DirectoryFetcher::fetch_files_async creates unbounded Vec<DirectoryItem> (~4.71GB): When a directory contains an extremely large number of files, all entries are converted to DirectoryItem objects with no limit. Adding a cap of 10,000 entries prevents the unbounded allocation while still being more than sufficient for UI display purposes.

Heap profile evidence (event 1e605502188449c19fa61c71475beb66):

  • Vec<DirectoryItem>::from_iter via DirectoryFetcher::fetch_files_async: 4.71GB (52%)
  • DashMap::clone via SessionContext::clone: 2.36GB (26%)
  • Total RSS: 9.06GB

Linked Issue

Testing

  • cargo check -p warp --lib passes
  • cargo clippy -p warp --lib -- -D warnings passes
  • cargo fmt -- --check passes

Agent Mode

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

Conversation: https://staging.warp.dev/conversation/444c97c2-e0e9-4f82-8ee8-70e5bf987717
Run: https://oz.staging.warp.dev/runs/019e55a1-427e-7d3e-9b1d-e054750250ec
This PR was generated with Oz.

Two changes to address excessive memory usage (9.06GB) observed in Sentry
issue 7259255054:

1. Wrap cached_directory_entries DashMap in Arc in SessionContext so that
   cloning SessionContext is O(1) instead of deep-copying the entire
   directory cache. The heap profile showed SessionContext::clone()
   allocating ~2.36GB from DashMap deep-copy.

2. Cap DirectoryFetcher::fetch_files_async at 10,000 entries to prevent
   unbounded Vec<DirectoryItem> allocation. The heap profile showed
   Vec<DirectoryItem>::from_iter consuming ~4.71GB (52% of total).

Sentry: https://sentry.io/organizations/warpdotdev/issues/7259255054/

Co-Authored-By: Oz <oz-agent@warp.dev>
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