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): use a reverse lookup in forgetTransientResolutions #5372

Merged
merged 1 commit into from
Apr 24, 2023

Conversation

merceyz
Copy link
Member

@merceyz merceyz commented Apr 7, 2023

What's the problem this PR addresses?

When Project.forgetResolution is called with a locator it loops over Project.storedResolutions to find all descriptors that point to that locator, this becomes expensive when called multiple times, which Project.forgetTransientResolutions potentially does.

How did you fix it?

Create a reverse mapping of Project.storedResolutions to efficiently lookup all descriptors pointing to a locator and delete them directly in Project.forgetTransientResolutions.

Results

Tested on the DefinitelyTyped repo with its 8629 workspaces (matching only types/*):

$ 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 ± σ):     15.802 s ±  0.437 s    [User: 12.243 s, System: 10.097 s]
  Range (min … max):   14.979 s … 16.265 s    10 runs

Benchmark 2: node ./before.cjs --mode skip-build
  Time (mean ± σ):     17.260 s ±  0.471 s    [User: 13.692 s, System: 9.957 s]
  Range (min … max):   16.425 s … 18.000 s    10 runs

Summary
  'node ./after.cjs --mode skip-build' ran
    1.09 ± 0.04 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 318cfc3 into master Apr 24, 2023
@arcanis arcanis deleted the merceyz/perf/forget-resolution branch April 24, 2023 15:14
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