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

esm: synchronise default path of ModuleLoader.load #57390

Closed
wants to merge 2 commits into from

Conversation

JakobJingleheimer
Copy link
Member

No description provided.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Mar 9, 2025
context = { __proto__: context, source };
}

if (format == null) {
// Now that we have the source for the module, run `defaultGetFormat` to detect its format.
format = await defaultGetFormat(urlInstance, context);
format = defaultGetFormat(urlInstance, context);
Copy link
Member Author

Choose a reason for hiding this comment

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

defaultGetFormat is already sync

@JakobJingleheimer JakobJingleheimer changed the title esm: synchronise ModuleLoader esm: synchronise ModuleLoader.load Mar 9, 2025
@JakobJingleheimer JakobJingleheimer changed the title esm: synchronise ModuleLoader.load esm: synchronise default path of ModuleLoader.load Mar 9, 2025
const { readFile: readFileAsync } = require('internal/fs/promises').exports;
source = await readFileAsync(url);
source = readFileSync(url);
Copy link
Member Author

Choose a reason for hiding this comment

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

This converts to a blocking op, but I'm not sure if that matters.

Copy link
Member

Choose a reason for hiding this comment

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

The CommonJS loadSource uses readFileSync:

return fs.readFileSync(filename, 'utf8');

though CommonJS is fundamentally sync. I think it should be fine to use the same in ESM; @joyeecheung or anyone else, do you have any concerns?

Copy link
Member

Choose a reason for hiding this comment

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

Blocking fs is generally not problematic when your fs is fast enough (and not taking on the async overhead might make it faster, as nodejs/performance#151 shows).

Copy link
Member

@GeoffreyBooth GeoffreyBooth left a comment

Choose a reason for hiding this comment

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

+1 to the effort. Tracking issue: #55782

We should also find some benchmarks that measure the performance impact of the overall syncification effort. Perhaps the existing ESM benchmarks are sufficient?

const { readFile: readFileAsync } = require('internal/fs/promises').exports;
source = await readFileAsync(url);
source = readFileSync(url);
Copy link
Member

Choose a reason for hiding this comment

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

The CommonJS loadSource uses readFileSync:

return fs.readFileSync(filename, 'utf8');

though CommonJS is fundamentally sync. I think it should be fine to use the same in ESM; @joyeecheung or anyone else, do you have any concerns?

@JakobJingleheimer JakobJingleheimer marked this pull request as ready for review March 10, 2025 21:18
Copy link

codecov bot commented Mar 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.11%. Comparing base (9df0ff7) to head (9f14b39).
Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57390      +/-   ##
==========================================
- Coverage   90.23%   90.11%   -0.12%     
==========================================
  Files         630      630              
  Lines      185200   185193       -7     
  Branches    36233    36165      -68     
==========================================
- Hits       167108   166882     -226     
- Misses      11056    11239     +183     
- Partials     7036     7072      +36     
Files with missing lines Coverage Δ
lib/internal/modules/esm/load.js 91.91% <100.00%> (-0.04%) ⬇️
lib/internal/modules/esm/loader.js 95.04% <100.00%> (ø)

... and 49 files with indirect coverage changes

🚀 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.

@JakobJingleheimer
Copy link
Member Author

This PR got created wrong, so I had to create a new one to update it: #57419

Apologies for the noise 😞

@JakobJingleheimer JakobJingleheimer deleted the esm/synchify-module-loader branch March 12, 2025 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants