Skip to content

Comments

perf(ProjectManager): cache PathCollection per project in flushDocumentChanges#1628

Open
bartvandenende-wm wants to merge 1 commit intorokucommunity:masterfrom
bartvandenende-wm:feature/cache-project-path-collection
Open

perf(ProjectManager): cache PathCollection per project in flushDocumentChanges#1628
bartvandenende-wm wants to merge 1 commit intorokucommunity:masterfrom
bartvandenende-wm:feature/cache-project-path-collection

Conversation

@bartvandenende-wm
Copy link
Contributor

@bartvandenende-wm bartvandenende-wm commented Feb 15, 2026

Context

In large multi-project workspaces, every document flush recompiles glob matchers for every project, even though file patterns rarely change. This is part 3 of 3 targeted improvements to language server performance at scale (Part of #1625).

Summary

Caches PathCollection instances per project to avoid redundant micromatch.matcher() compilation on every document flush.

  • Uses a WeakMap to lazily create and cache PathCollection per project
  • File patterns only change on project reload, so the cache stays valid for the project's lifetime
  • Cached instances are automatically garbage-collected when the project is removed

Test plan

  • New tests verify PathCollection instances are reused across flushes
  • Existing flushDocumentChanges tests pass unchanged

…ntChanges

Previously, every document flush created a new PathCollection for each
project to filter which files belong to that project. In workspaces with
many projects and frequent file changes, this caused unnecessary
allocations and glob compilation overhead.

Cache the PathCollection per project using a WeakMap. The cache is
automatically invalidated when a project is removed (and garbage
collected). File patterns only change when a project is reloaded, so
the cached filterer remains valid for the lifetime of the project.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant