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

Tracking Issue: Syncify the ESM Loader #55782

Open
21 tasks
GeoffreyBooth opened this issue Nov 8, 2024 · 3 comments
Open
21 tasks

Tracking Issue: Syncify the ESM Loader #55782

GeoffreyBooth opened this issue Nov 8, 2024 · 3 comments
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders performance Issues and PRs related to the performance of Node.js.

Comments

@GeoffreyBooth
Copy link
Member

GeoffreyBooth commented Nov 8, 2024

The code under lib/internal/modules/esm, a.k.a. the ESM loader, contains many functions that are async. We should refactor as many of these as possible, ideally all of them, to be synchronous. This should improve the performance of evaluating ESM code, bringing it roughly on par with the speed of running CommonJS code.

Longer term, once the ESM loader is synchronous and we land the synchronous module customization hooks, we could deprecate monkey-patching the CommonJS loader and merge together the CommonJS and ESM loaders, eliminating duplication: #50356.

This issue will track our progress syncifying the various files and functions of the ESM loader until we can get as much of it to be as synchronous as possible.

The files to be updated, all underlib/internal/modules:

  • run_main.js: asyncRunEntryPointWithESMLoader
  • esm/fetch_module.js: fetchWithRedirects
  • esm/fetch_module.js: isLocalAddress
  • esm/hooks.js: Hooks class (the async methods here probably don’t need updating as they will be removed once we migrate to the synchronous customization hooks)
  • esm/hooks.js: nextHookFactory
  • esm/load.js: getSource
  • esm/load.js: defaultLoad
  • esm/loader.js: ModuleLoader.eval
  • esm/loader.js: ModuleLoader.getModuleJobForImport
  • esm/loader.js: ModuleLoader.loadAndTranslate
  • esm/loader.js: ModuleLoader.import
  • esm/loader.js: ModuleLoader.load
  • esm/module_job.js: ModuleJob._link
  • esm/module_job.js: ModuleJob._instantiate
  • esm/module_job.js: ModuleJob.run
  • esm/module_job.js: ModuleJobSync.run
  • esm/translators.js: wasm handler, via translators.set('wasm', ...
  • esm/utils.js: importModuleDynamicallyCallback
  • esm/utils.js: initializeHooks (might not need updating as we will remove this once the synchronous customization hooks land
  • esm/worker.js: customizedModuleWorker (might not need updating as we will remove this once the synchronous customization hooks land
  • esm/worker.js: handleMessage (might not need updating as we will remove this once the synchronous customization hooks land

@nodejs/loaders @mcollina @JakobJingleheimer @joyeecheung

@GeoffreyBooth GeoffreyBooth added esm Issues and PRs related to the ECMAScript Modules implementation. performance Issues and PRs related to the performance of Node.js. labels Nov 8, 2024
@marco-ippolito
Copy link
Member

marco-ippolito commented Nov 8, 2024

Maybe moving it in the loaders repo would be more appropriate since its a effort that is gonna require different iterations?

@mcollina
Copy link
Member

mcollina commented Nov 8, 2024

This task is better handled by a large group of people, and this repo is more visible. Once the first few steps are done, it can easily be tagged as "good first issue"

@RedYetiDev RedYetiDev added the loaders Issues and PRs related to ES module loaders label Nov 8, 2024
@nomagick
Copy link

I would like to mention my issue here.
Please check if it's worth fixing.

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. loaders Issues and PRs related to ES module loaders performance Issues and PRs related to the performance of Node.js.
Projects
None yet
Development

No branches or pull requests

5 participants