Fix Yarn detector perf#1849
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.
grvillic
enabled auto-merge (squash)
July 15, 2026 08:14
RushabhBhansali
approved these changes
Jul 15, 2026
|
👋 Hi! It looks like you modified some files in the
If none of the above scenarios apply, feel free to ignore this comment 🙂 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
We got reports from a couple of mono repos using Yarn that the performance was incredibly slow, which is surprising given the detector is only reading files from disk without any CLI nor network calls, we had a bottleneck somewhere.
Summary
On a Yarn Berry monorepo with a 2.2 MB / ~55k-line yarn.lock, 4,809 lockfile entries, and 594 workspace patterns a Yarn-only scan took ~94 minutes.
After a targeted fix scoped exclusively to the Yarn detector, the same scan completes in ~15 seconds while producing byte-identical results.
Root cause
YarnLockComponentDetector.GetWorkspaceDependenciesran a full recursive filesystem walk once per workspace pattern. With 594 workspace patterns, it walked the entire monorepo tree, including a very large node_modules, 594 times. Cost was O(patterns × filesystem size).Fix
Update
src/Microsoft.ComponentDetection.Detectors/yarn/YarnLockComponentDetector.csto perform a single recursive filesystem traversal, discovering and parsing each candidate package.json exactly once, matched against a union matcher of all workspace globs.Replay dependency resolution in the original order (workspace-pattern order, then discovery order) so the "first-wins" location attribution stays identical to the previous per-pattern behavior.
Net effect: 594 filesystem walks → 1 walk. No change to which components, graph edges, dev flags, or roots are produced.
Results