Skip to content

Conversation

@Angelmmiguel
Copy link
Contributor

@Angelmmiguel Angelmmiguel commented Nov 6, 2025

Optimize project root detection by caching the result of findProjectRoot() to avoid redundant Git subprocess calls. Previously, this function executed a Git command on every invocation, which could happen multiple times during a single CLI command execution across different modules.

This change introduces a module-level cache that stores the project root after the first call, eliminating unnecessary Git operations for subsequent invocations. A clearProjectRootCache() function is also provided for testing scenarios and edge cases where the repository root might change.

Closes #265

Changes

  • Added caching mechanism to findProjectRoot() in packages/common/src/os.ts using module-level variable
  • Implemented clearProjectRootCache() utility function to invalidate the cache when needed

Notes

The cache is stored at the module level and persists for the lifetime of the process. This is safe for CLI usage since each command invocation is a separate process. For long-running processes (like the VS Code extension), clearProjectRootCache() can be called when the workspace changes to ensure the cache stays valid.

@Angelmmiguel Angelmmiguel changed the title perf: cache project root detection to avoid redundant Git operations chore: cache project root detection to avoid redundant Git operations Nov 6, 2025
@Angelmmiguel Angelmmiguel self-assigned this Nov 6, 2025
@Angelmmiguel Angelmmiguel added this to the v1.5 milestone Nov 6, 2025
@Angelmmiguel Angelmmiguel merged commit 6f119b0 into main Nov 10, 2025
4 checks passed
@Angelmmiguel Angelmmiguel deleted the rover/task-123-M-jTIzvgzE4f branch December 5, 2025 10:56
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.

Cache findProjectRoot result to avoid redundant Git operations

3 participants