Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(core): setup workspaces in parallel #5367

Merged
merged 1 commit into from
Apr 6, 2023
Merged

Conversation

merceyz
Copy link
Member

@merceyz merceyz commented Apr 2, 2023

What's the problem this PR addresses?

Yarn loads workspaces one at a time which when you get to 1000s of workspaces noticeably slows down the project setup.

How did you fix it?

Changed the loading from a breadth-first one at a time to a depth-first multiple at a time load

Results

When I implemented and tested this on the Next.js repo with all examples included (291 workspaces) back in 2020-12-04 it didn't have much of an impact

$ YARN_IGNORE_PATH=1 hyperfine -w 1\
  "node ./master.cjs --mode update-lockfile"\
  "node ./async-setup.cjs --mode update-lockfile"\
  "node ./async-setup-no-limit.cjs --mode update-lockfile"
Benchmark 1: node ./master.cjs --mode update-lockfile
  Time (mean ± σ):      3.041 s ±  0.026 s    [User: 4.153 s, System: 0.344 s]
  Range (min … max):    3.015 s …  3.108 s    10 runs

Benchmark 2: node ./async-setup.cjs --mode update-lockfile
  Time (mean ± σ):      3.010 s ±  0.019 s    [User: 4.193 s, System: 0.281 s]
  Range (min … max):    2.987 s …  3.046 s    10 runs

Benchmark 3: node ./async-setup-no-limit.cjs --mode update-lockfile
  Time (mean ± σ):      3.135 s ±  0.039 s    [User: 4.108 s, System: 0.313 s]
  Range (min … max):    3.079 s …  3.208 s    10 runs

Summary
  'node ./async-setup.cjs --mode update-lockfile' ran
    1.01 ± 0.01 times faster than 'node ./master.cjs --mode update-lockfile'
    1.04 ± 0.01 times faster than 'node ./async-setup-no-limit.cjs --mode update-lockfile'

however this improvement scales so on the DefinitelyTyped repo with its 8629 workspaces (matching only types/*) it's more noticeable.

$ YARN_IGNORE_PATH=1 hyperfine -w 1 "node ./after.cjs --mode skip-build" "node ./before.cjs --mode skip-build"
Benchmark 1: node ./after.cjs --mode skip-build
  Time (mean ± σ):     14.926 s ±  0.065 s    [User: 12.219 s, System: 9.392 s]
  Range (min … max):   14.874 s … 15.088 s    10 runs

Benchmark 2: node ./before.cjs --mode skip-build
  Time (mean ± σ):     16.095 s ±  0.500 s    [User: 12.787 s, System: 9.733 s]
  Range (min … max):   15.573 s … 16.728 s    10 runs

Summary
  'node ./after.cjs --mode skip-build' ran
    1.08 ± 0.03 times faster than 'node ./before.cjs --mode skip-build'

Checklist

  • I have read the Contributing Guide.
  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@arcanis arcanis merged commit a54fb26 into master Apr 6, 2023
@arcanis arcanis deleted the merceyz/perf/async-setup branch April 6, 2023 16:26
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.

2 participants