Skip to content

lib: merge cjs and esm package json reader caches - #48477

Merged
nodejs-github-bot merged 9 commits into
nodejs:mainfrom
anonrig:refactor-package-json
Jun 29, 2023
Merged

lib: merge cjs and esm package json reader caches#48477
nodejs-github-bot merged 9 commits into
nodejs:mainfrom
anonrig:refactor-package-json

Conversation

@anonrig

@anonriganonrig commented Jun 16, 2023

Copy link
Copy Markdown
Member

This PR contains a refactor to merge package.json reader caches in both CJS and ESM.

I extracted the relevant parts from #47991.

cc @nodejs/loaders @nodejs/modules

PS: This PR has no effect on execution speed.

hyperfine './out/Release/node ../fastify/fastify.js' 'node ../fastify/fastify.js' 'bun ../fastify/fastify.js' -i --warmup 10
Benchmark 1: ./out/Release/node ../fastify/fastify.js
Time (mean ± σ): 88.3 ms ± 1.8 ms [User: 85.5 ms, System: 20.3 ms]
Range (min … max): 84.7 ms … 94.8 ms 33 runs
Benchmark 2: node ../fastify/fastify.js
Time (mean ± σ): 88.8 ms ± 2.1 ms [User: 83.2 ms, System: 21.8 ms]
Range (min … max): 84.0 ms … 95.0 ms 33 runs
Benchmark 3: bun ../fastify/fastify.js
Time (mean ± σ): 99.6 ms ± 1.5 ms [User: 84.5 ms, System: 19.9 ms]
Range (min … max): 98.3 ms … 103.6 ms 29 runs
Summary
./out/Release/node ../fastify/fastify.js ran
1.01 ± 0.03 times faster than node ../fastify/fastify.js
1.13 ± 0.03 times faster than bun ../fastify/fastify.js

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/modules

@nodejs-github-botnodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jun 16, 2023
@anonrig
anonrigforce-pushed the refactor-package-json branch 3 times, most recently from d6a4186 to 24d52e6CompareJune 16, 2023 22:48
Comment threadlib/internal/modules/package_json_reader.js Outdated

@JakobJingleheimerJakobJingleheimer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 🙌

Comment threadlib/internal/modules/package_json_reader.js Outdated
Comment threadlib/internal/modules/package_json_reader.js Outdated
Comment threadlib/internal/modules/cjs/loader.js Outdated

@JakobJingleheimerJakobJingleheimer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good aside from the the new susceptibility to prototype pollution

Comment threadlib/internal/modules/cjs/loader.js Outdated
Comment threadlib/internal/modules/esm/package_config.js Outdated
Comment threadlib/internal/modules/esm/package_config.js Outdated
Comment threadlib/internal/modules/esm/resolve.js Outdated

@GeoffreyBoothGeoffreyBooth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see a bunch of C++ got removed, should we do a benchmark?

Nevermind, I see it in the top post 😄

@anonriganonrig added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Jun 21, 2023
@anonrig
anonrigforce-pushed the refactor-package-json branch from 0b605b8 to d4e2a4eCompareJune 21, 2023 16:58
@anonrig

Copy link
Copy Markdown
MemberAuthor

I fixed the conflict, and force pushed it. Appreciate reviewing it again.

@anonriganonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 21, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@GeoffreyBoothGeoffreyBooth added the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 29, 2023
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 29, 2023
@nodejs-github-bot
nodejs-github-bot merged commit 951da52 into nodejs:mainJun 29, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 951da52

RafaelGSS pushed a commit that referenced this pull request Jul 3, 2023
PR-URL: #48477
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@RafaelGSSRafaelGSS mentioned this pull request Jul 3, 2023
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
PR-URL: nodejs#48477
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
PR-URL: nodejs#48477
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@ruyadorno

Copy link
Copy Markdown
Member

This commit does not land cleanly on v18.x-staging and will need manual backport in case we want it in v18.

targos pushed a commit to targos/node that referenced this pull request Nov 11, 2023
PR-URL: nodejs#48477
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
targos pushed a commit that referenced this pull request Nov 23, 2023
PR-URL: #48477
Backport-PR-URL: #50669
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@targostargos mentioned this pull request Nov 28, 2023
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
PR-URL: nodejs/node#48477
Backport-PR-URL: nodejs/node#50669
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
PR-URL: nodejs/node#48477
Backport-PR-URL: nodejs/node#50669
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.lib / srcIssues and PRs related to general changes in the lib or src directory.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

13 participants

@anonrig@nodejs-github-bot@richardlau@aduh95@ruyadorno@ljharb@mcollina@GeoffreyBooth@arcanis@JakobJingleheimer@RafaelGSS@VoltrexKeyva@targos