Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf!: lazy load
packageExtensions
(#5608)
**What's the problem this PR addresses?** <!-- Describe the rationale of your PR. --> <!-- Link all issues that it closes. (Closes/Resolves #xxxx.) --> Loading `packageExtensions` is currently done every single time `Configuration.find` is called, and it adds considerable overhead, both on every `yarn` invocation and even more on commands that don't even use the `packageExtensions`, such as `yarn run`. **How did you fix it?** <!-- A detailed description of your implementation. --> This PR gets rid of the `packageExtensions` field and the `refreshPackageExtensions` method in favor of a `configuration.getPackageExtensions` async method that caches the extensions and is called directly when needing access to `packageExtensions`. ~~This change requires `configuration.normalizePackage` to become `async`, but that's not a problem since all its callers are `async`.~~ See review discussion. Note: `packageExtensions` can't be a lazy getter because `packageExtensions` need to be loaded asynchronously. Benchmarks: - `yarn -v`: ```js YARN_IGNORE_PATH=1 hyperfine 'node ./before.cjs --version' 'node ./after.cjs --version' Benchmark 1: node ./before.cjs --version Time (mean ± σ): 153.8 ms ± 2.0 ms [User: 160.5 ms, System: 35.4 ms] Range (min … max): 150.7 ms … 158.4 ms 19 runs Benchmark 2: node ./after.cjs --version Time (mean ± σ): 141.1 ms ± 1.3 ms [User: 148.4 ms, System: 33.4 ms] Range (min … max): 137.1 ms … 143.1 ms 21 runs Summary 'node ./after.cjs --version' ran 1.09 ± 0.02 times faster than 'node ./before.cjs --version' ``` - `yarn workspaces foreach run` ```js Benchmark 1: node ./before.cjs workspaces foreach run Time (mean ± σ): 5.997 s ± 0.066 s [User: 7.707 s, System: 1.831 s] Range (min … max): 5.870 s … 6.072 s 10 runs Benchmark 2: node ./after.cjs workspaces foreach run Time (mean ± σ): 5.887 s ± 0.072 s [User: 7.533 s, System: 1.683 s] Range (min … max): 5.769 s … 5.977 s 10 runs Summary 'node ./after.cjs workspaces foreach run' ran 1.02 ± 0.02 times faster than 'node ./before.cjs workspaces foreach run' ``` **Checklist** <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [X] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [X] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [X] I will check that all automated PR checks pass before the PR gets reviewed. --------- Co-authored-by: Maël Nison <[email protected]>
- Loading branch information