fix: eliminate gitignore regex cache memory spike in build_tree (APP-4522)
Description
Fix a memory spike (~12 GB heap) caused by excessive regex_automata PikeVM cache allocations during gitignore matching in Entry::build_tree.
Root Cause
Sentry issue: https://warpdotdev.sentry.io/issues/7259255054/
Heap profile: 97% of 12.63 GB in-use heap traced to repo_metadata::entry::matches_gitignores → regex_automata::nfa::thompson::pikevm::ActiveStates::reset.
When Warp builds the file tree for a repo, it carries a list of active .gitignore matchers down the directory traversal. Before this PR, matchers from one subtree could stay in that list while traversing sibling directories. That meant later siblings did extra gitignore checks against rules that could never apply to them, increasing CPU work and memory used by regex caches.
Fix
This PR treats the active .gitignore list like a stack:
- remember how many matchers were active before entering a path
- add that path’s
.gitignore, if present - restore the previous matcher count before returning to the parent
This keeps each directory traversal scoped to only the .gitignore files that can apply to that path.
Linked Issue
Testing
- [ ] I have manually tested my changes locally with
./script/run
Agent Mode
- [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode
CHANGELOG-BUG-FIX: Fixed a memory spike during codebase indexing caused by excessive gitignore regex matching.
Initial Conversation: https://staging.warp.dev/conversation/bdfc48bd-3a06-412c-a5fe-68b9bf1f299b Initial Run: https://oz.staging.warp.dev/runs/019e4435-d50d-7b65-b71e-bb0e15dffd0d
This PR was generated with Oz.