Skip to content

Fix Yarn detector perf#1849

Merged
grvillic merged 1 commit into
mainfrom
users/grvillic/FixYarnPerformance
Jul 15, 2026
Merged

Fix Yarn detector perf#1849
grvillic merged 1 commit into
mainfrom
users/grvillic/FixYarnPerformance

Conversation

@grvillic

Copy link
Copy Markdown
Collaborator

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.GetWorkspaceDependencies ran 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.cs to 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

Run Detection time
Baseline (before fix) 5652.6 s (~94 min)
Improved ( filesystem cache) 15.5 s

@grvillic
grvillic requested a review from a team as a code owner July 15, 2026 08:14
@grvillic
grvillic requested review from JamieMagee and Copilot July 15, 2026 08:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
grvillic enabled auto-merge (squash) July 15, 2026 08:14
@grvillic
grvillic merged commit c0bfb33 into main Jul 15, 2026
15 checks passed
@grvillic
grvillic deleted the users/grvillic/FixYarnPerformance branch July 15, 2026 15:01
@github-actions

Copy link
Copy Markdown

👋 Hi! It looks like you modified some files in the Detectors folder.
You may need to bump the detector versions if any of the following scenarios apply:

  • The detector detects more or fewer components than before
  • The detector generates different parent/child graph relationships than before
  • The detector generates different devDependencies values than before

If none of the above scenarios apply, feel free to ignore this comment 🙂

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.

3 participants