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(pnp): hoist data string #4320

Merged
merged 1 commit into from
Apr 3, 2022
Merged

perf(pnp): hoist data string #4320

merged 1 commit into from
Apr 3, 2022

Conversation

merceyz
Copy link
Member

@merceyz merceyz commented Apr 3, 2022

What's the problem this PR addresses?

#3977 improved the startup time of the PnP hook but we can do more.

How did you fix it?

Hoist the data string to the top level to avoid V8 parsing it multiple times. https://v8.dev/blog/preparser

Benchmark results

Gatsby benchmark:

hyperfine -w 5 "node -r ./.pnp-before.cjs -e 1" "node -r ./.pnp-after.cjs -e 1"
Benchmark 1: node -r ./.pnp-before.cjs -e 1
  Time (mean ± σ):      52.4 ms ±   1.2 ms    [User: 53.3 ms, System: 8.7 ms]
  Range (min … max):    51.1 ms …  56.4 ms    57 runs

Benchmark 2: node -r ./.pnp-after.cjs -e 1
  Time (mean ± σ):      48.5 ms ±   0.5 ms    [User: 48.0 ms, System: 9.9 ms]
  Range (min … max):    47.5 ms …  49.7 ms    61 runs

Summary
  'node -r ./.pnp-after.cjs -e 1' ran
    1.08 ± 0.03 times faster than 'node -r ./.pnp-before.cjs -e 1'

Next.js repo:

hyperfine -w 5 "node -r ./.pnp-before.cjs -e 1" "node -r ./.pnp-after.cjs -e 1"
Benchmark 1: node -r ./.pnp-before.cjs -e 1
  Time (mean ± σ):     134.5 ms ±   0.9 ms    [User: 144.2 ms, System: 22.8 ms]
  Range (min … max):   132.6 ms … 137.4 ms    22 runs

Benchmark 2: node -r ./.pnp-after.cjs -e 1
  Time (mean ± σ):     110.6 ms ±   0.9 ms    [User: 120.9 ms, System: 22.1 ms]
  Range (min … max):   109.4 ms … 112.5 ms    26 runs

Summary
  'node -r ./.pnp-after.cjs -e 1' ran
    1.22 ± 0.01 times faster than 'node -r ./.pnp-before.cjs -e 1'

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 ea27848 into master Apr 3, 2022
@arcanis arcanis deleted the merceyz/perf/hoist-pnp-data branch April 3, 2022 19:02
@merceyz merceyz added the major label Apr 3, 2022
@merceyz merceyz mentioned this pull request Apr 3, 2022
13 tasks
@merceyz merceyz added this to the 4.0.0 milestone May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants