这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Nov 16, 2025

In cjs, the spec states

LOAD_NODE_MODULES(X, START)
1. let DIRS = NODE_MODULES_PATHS(START)
2. for each DIR in DIRS:
   a. LOAD_PACKAGE_EXPORTS(X, DIR)
   b. LOAD_AS_FILE(DIR/X)
   c. LOAD_AS_DIRECTORY(DIR/X)

2.b. LOAD_AS_FILE(DIR/X) never occurs in modern package managers, and I do not recall any circumstance that creates a lone node_modules/X.js file.

This reduces a package lookup from

node_modules/X.js
node_modules/X.json
node_modules/X.node
node_modules/X/index.js

to

node_modules/X/
(if X failed)
node_modules/X.js
node_modules/X.json
node_modules/X.node

NOTE: ESM does not have LOAD_AS_FILE(DIR/X) logic.


This change was introduced from

  • https://github.com/oxc-project/oxc-resolver/pull/592
  • https://github.com/unrs/unrs-resolver/pull/116

These PRs do not explain a real case for node_modules/X.js to accept such performance regression.

@graphite-app
Copy link

graphite-app bot commented Nov 16, 2025

How to use the Graphite Merge Queue

Add the label merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 16, 2025

CodSpeed Performance Report

Merging #839 will improve performances by 6.51%

Comparing 11-16-perf_fast_path_for_node_modules_package (f513bbd) with main (ff6e393)1

Summary

⚡ 4 improvements
✅ 7 untouched
⏩ 5 skipped2

Benchmarks breakdown

Benchmark BASE HEAD Change
resolver_memory[multi-thread] 509.8 µs 494.5 µs +3.11%
resolver_memory[single-thread] 500.2 µs 477.8 µs +4.67%
resolver_real[multi-thread] 521.1 µs 489.2 µs +6.51%
resolver_real[single-thread] 497.4 µs 473.3 µs +5.09%

Footnotes

  1. No successful run was found on main (f513bbd) during the generation of this report, so ff6e393 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Boshen Boshen force-pushed the 11-16-perf_fast_path_for_node_modules_package branch from 2d1ef5d to 3afbefa Compare November 16, 2025 14:26
@Boshen Boshen requested a review from sapphi-red November 16, 2025 14:26
@Boshen Boshen marked this pull request as ready for review November 16, 2025 14:26
@codecov
Copy link

codecov bot commented Nov 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.90%. Comparing base (ff6e393) to head (f513bbd).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #839      +/-   ##
==========================================
+ Coverage   93.88%   93.90%   +0.02%     
==========================================
  Files          17       17              
  Lines        3091     3086       -5     
==========================================
- Hits         2902     2898       -4     
+ Misses        189      188       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Boshen Boshen force-pushed the 11-16-perf_fast_path_for_node_modules_package branch from 3afbefa to 59ab98c Compare November 16, 2025 14:43
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

I agree that this won't be a problem in practice. I think it'd be nice to mention this somewhere in the README as it differs from how Node resolves.

@sapphi-red
Copy link
Member

I guess the other thing that oxc-resolver doesn't support is the NODE_PATH env var.

@Boshen
Copy link
Member Author

Boshen commented Nov 17, 2025

I guess the other thing that oxc-resolver doesn't support is the NODE_PATH env var.

never heard of NODE_PATH lol

@sapphi-red
Copy link
Member

Many legacy things in CJS 😄. It is this: https://nodejs.org/api/modules.html#loading-from-the-global-folders

@Boshen Boshen added the merge label Nov 17, 2025
Copy link
Member Author

Boshen commented Nov 17, 2025

Merge activity

In cjs, the spec states

```
LOAD_NODE_MODULES(X, START)
1. let DIRS = NODE_MODULES_PATHS(START)
2. for each DIR in DIRS:
   a. LOAD_PACKAGE_EXPORTS(X, DIR)
   b. LOAD_AS_FILE(DIR/X)
   c. LOAD_AS_DIRECTORY(DIR/X)
```

`2.b. LOAD_AS_FILE(DIR/X)` never occurs in modern package managers, and I do not recall any circumstance that creates a lone `node_modules/X.js` file.

This reduces a package lookup from

```
node_modules/X.js
node_modules/X.json
node_modules/X.node
node_modules/X/index.js
```

to

```
node_modules/X/
(if X failed)
node_modules/X.js
node_modules/X.json
node_modules/X.node
```

NOTE: ESM does not have `LOAD_AS_FILE(DIR/X)` logic.

---

This change was introduced from

- `https://github.com/oxc-project/oxc-resolver/pull/592`
- `https://github.com/unrs/unrs-resolver/pull/116`

These PRs do not explain a real case for `node_modules/X.js` to accept such performance regression.
@graphite-app graphite-app bot force-pushed the 11-16-perf_fast_path_for_node_modules_package branch from 59ab98c to f513bbd Compare November 17, 2025 05:52
@graphite-app graphite-app bot merged commit f513bbd into main Nov 17, 2025
17 checks passed
@graphite-app graphite-app bot deleted the 11-16-perf_fast_path_for_node_modules_package branch November 17, 2025 05:54
@graphite-app graphite-app bot removed the merge label Nov 17, 2025
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.

3 participants