Skip to content

Conversation

merceyz
Copy link
Member

@merceyz merceyz commented Jun 3, 2023

What's the problem this PR addresses?

We're unnecessarily patching Module._load more than we need to which skips important optimisations in Node.js.

Fixes #4301

How did you fix it?

Use the default Module._load when the request isn't pnpapi.

Results

$ hyperfine -w 1 "cd berry-before && yarn test:lint" "cd berry && yarn test:lint"
Benchmark 1: cd berry-before && yarn test:lint
  Time (mean ± σ):     18.475 s ±  0.400 s    [User: 25.934 s, System: 1.695 s]
  Range (min … max):   18.010 s … 19.249 s    10 runs

Benchmark 2: cd berry && yarn test:lint
  Time (mean ± σ):     14.187 s ±  0.144 s    [User: 21.348 s, System: 1.504 s]
  Range (min … max):   13.929 s … 14.409 s    10 runs

Summary
  'cd berry && yarn test:lint' ran
    1.30 ± 0.03 times faster than 'cd berry-before && yarn test:lint'

$ hyperfine -w 1 "cd berry-before && yarn --version" "cd berry && yarn --version"
Benchmark 1: cd berry-before && yarn --version
  Time (mean ± σ):      2.011 s ±  0.010 s    [User: 1.833 s, System: 0.582 s]
  Range (min … max):    2.001 s …  2.029 s    10 runs

Benchmark 2: cd berry && yarn --version
  Time (mean ± σ):      1.866 s ±  0.009 s    [User: 1.726 s, System: 0.538 s]
  Range (min … max):    1.856 s …  1.886 s    10 runs

Summary
  'cd berry && yarn --version' ran
    1.08 ± 0.01 times faster than 'cd berry-before && yarn --version'

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.

@merceyz merceyz marked this pull request as ready for review June 3, 2023 21:24
@merceyz merceyz requested a review from arcanis as a code owner June 3, 2023 21:24
Comment on lines 12 to 13
- packages/yarnpkg-pnp/sources/hook.js
- packages/yarnpkg-pnp/sources/esm-loader/built-loader.js
Copy link
Member

Choose a reason for hiding this comment

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

That will cause the E2E tests to run inside many PRs; the idea was to only run them inside the master branch, to avoid using too many GH Action resources. At the very least, should be moved to a separate PR to make a rollback easier.

Copy link
Member Author

@merceyz merceyz Jun 7, 2023

Choose a reason for hiding this comment

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

I'll revert it but that was the point, to catch potential issues with changes to the PnP hook earlier.

arcanis
arcanis previously approved these changes Jun 7, 2023
Copy link
Member

@arcanis arcanis left a comment

Choose a reason for hiding this comment

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

✅ minus the E2E part

@arcanis arcanis merged commit 16b0ca7 into master Jun 16, 2023
@arcanis arcanis deleted the merceyz/perf/pnp-module-load branch June 16, 2023 08:50
merceyz added a commit that referenced this pull request Jun 16, 2023
**What's the problem this PR addresses?**

We're unnecessarily patching `Module._load` more than we need to which
skips important optimisations in Node.js.

Fixes #4301

**How did you fix it?**

Use the default `Module._load` when the request isn't `pnpapi`.

**Results**

```console
$ hyperfine -w 1 "cd berry-before && yarn test:lint" "cd berry && yarn test:lint"
Benchmark 1: cd berry-before && yarn test:lint
  Time (mean ± σ):     18.475 s ±  0.400 s    [User: 25.934 s, System: 1.695 s]
  Range (min … max):   18.010 s … 19.249 s    10 runs

Benchmark 2: cd berry && yarn test:lint
  Time (mean ± σ):     14.187 s ±  0.144 s    [User: 21.348 s, System: 1.504 s]
  Range (min … max):   13.929 s … 14.409 s    10 runs

Summary
  'cd berry && yarn test:lint' ran
    1.30 ± 0.03 times faster than 'cd berry-before && yarn test:lint'

$ hyperfine -w 1 "cd berry-before && yarn --version" "cd berry && yarn --version"
Benchmark 1: cd berry-before && yarn --version
  Time (mean ± σ):      2.011 s ±  0.010 s    [User: 1.833 s, System: 0.582 s]
  Range (min … max):    2.001 s …  2.029 s    10 runs

Benchmark 2: cd berry && yarn --version
  Time (mean ± σ):      1.866 s ±  0.009 s    [User: 1.726 s, System: 0.538 s]
  Range (min … max):    1.856 s …  1.886 s    10 runs

Summary
  'cd berry && yarn --version' ran
    1.08 ± 0.01 times faster than 'cd berry-before && yarn --version'
```

**Checklist**
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have set the packages that need to be released for my changes to
be effective.
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.

---------

Co-authored-by: Maël Nison <[email protected]>
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.

[Bug?]: Repeated PnP require calls cause repeated existsSync, statSync, and readFileSync calls
2 participants