Skip to content

perf(vscode): optimize binary search for pnpm monorepos#17552

Closed
MIreland wants to merge 3 commits intooxc-project:mainfrom
MIreland:perf/vscode-optimize-binary-search-pnpm-monorepo
Closed

perf(vscode): optimize binary search for pnpm monorepos#17552
MIreland wants to merge 3 commits intooxc-project:mainfrom
MIreland:perf/vscode-optimize-binary-search-pnpm-monorepo

Conversation

@MIreland
Copy link

@MIreland MIreland commented Jan 1, 2026

Summary

Improves binary discovery performance in large pnpm monorepos by implementing two critical optimizations:

Changes

  1. Search all workspace folders instead of only the first one

    • Fixes issue where binary exists in a different workspace folder
    • Particularly important for multi-root workspaces in pnpm monorepos
  2. Check direct paths before recursive glob search

    • Try {workspace}/node_modules/.bin/{binary} directly first using fs.access()
    • Avoids expensive recursive search through hundreds/thousands of directories
    • In large monorepos with 800+ .bin directories, this provides significant performance improvement

New Search Strategy

The optimized strategy is:

  1. Fast path: Direct file access check in all workspace folders
  2. Fallback: Recursive glob search only if direct check fails
  3. Error handling: Gracefully handles timeouts and permission issues

Problem Solved

Fixes binary discovery failures in large pnpm monorepos (like orthlyweb) where:

  • oxlint is installed at the root node_modules/.bin/
  • The old logic only checked the first workspace folder
  • The recursive glob pattern **/node_modules/.bin/oxlint would timeout due to searching through 800+ .bin directories

Test Plan

  • ✅ All existing unit tests pass
  • ✅ Maintains backward compatibility with existing configurations
  • ✅ Tested compilation with TypeScript

Related Issues

This is the first PR in a series to improve VS Code extension performance in pnpm monorepos. See investigation notes in vscode-binary-discovery-issues.md (gitignored).

🤖 Generated with Claude Code

Improve binary discovery performance in large pnpm monorepos by:

1. Search all workspace folders instead of only the first one
   - Fixes issue where binary exists in a different workspace folder
   - Particularly important for multi-root workspaces

2. Check direct paths before recursive glob search
   - Try {workspace}/node_modules/.bin/{binary} directly first
   - Avoids expensive recursive search through hundreds of directories
   - In large monorepos with 800+ .bin directories, this provides
     significant performance improvement

The new search strategy:
- Fast path: Direct file access check in all workspace folders
- Fallback: Recursive glob search only if direct check fails
- Error handling: Gracefully handles timeouts and permission issues

Fixes binary discovery issues in pnpm monorepos like orthlyweb where
oxlint is installed at the root but the extension couldn't find it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 1, 2026 03:52
@MIreland MIreland requested a review from camc314 as a code owner January 1, 2026 03:52
@github-actions github-actions bot added A-editor Area - Editor and Language Server C-performance Category - Solution not expected to change functional behavior, only performance labels Jan 1, 2026
Remove investigation notes from .gitignore
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes binary discovery in pnpm monorepos by implementing two key improvements: searching all workspace folders instead of only the first one, and adding a fast-path direct file check before expensive recursive glob searches.

  • Replaces single-workspace binary search with multi-workspace iteration
  • Adds direct fs.access() check for node_modules/.bin/{binary} before glob search
  • Extracts binary search logic into a dedicated searchBinaryInWorkspaces method

Reviewed changes

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

File Description
editors/vscode/client/ConfigService.ts Refactors binary discovery to check all workspaces with optimized direct path checking before falling back to recursive glob search
.gitignore Adds investigation notes file to gitignore

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Addresses PR feedback:

1. Fix path format inconsistency
   - Convert directPath to proper file system path using Uri.file().fsPath
   - Ensures Windows paths use backslashes and proper drive letter format
   - Now both direct path check and glob search return consistently formatted paths

2. Add comprehensive test coverage for binary auto-discovery
   - Test finding binary in workspace node_modules/.bin/
   - Test returning undefined when binary not found
   - Test finding oxfmt binary in workspace
   - Test proper file system path formatting (Windows and Unix)
   - All 4 new tests passing (29 total tests passing)

The searchBinaryInWorkspaces method now has full test coverage for
the auto-discovery behavior when no explicit binary path is configured.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@MIreland
Copy link
Author

MIreland commented Jan 2, 2026

closing in favor of #17580

@MIreland MIreland closed this Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-editor Area - Editor and Language Server C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants