module: synchronously load most ES modules#62530
Open
GeoffreyBooth wants to merge 1 commit intonodejs:mainfrom
Open
module: synchronously load most ES modules#62530GeoffreyBooth wants to merge 1 commit intonodejs:mainfrom
GeoffreyBooth wants to merge 1 commit intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
2bb88f9 to
9a7728c
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62530 +/- ##
==========================================
- Coverage 89.71% 89.70% -0.01%
==========================================
Files 695 695
Lines 214108 214174 +66
Branches 40995 41016 +21
==========================================
+ Hits 192083 192124 +41
- Misses 14075 14104 +29
+ Partials 7950 7946 -4
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Building on #55782, this PR uses the path @joyeecheung created for
require(esm)to synchronously resolve and load all ES modules that lack top-levelawait, which is the vast majority of modules. The sync path is used when no async loader hooks,--importflags, or--inspect-brkare active; it falls back to the existing async path otherwise. Top-levelawaitpresence can only be determined after the module graph is instantiated, so if TLA is detected the already-instantiated graph falls back to async evaluation. In all cases the behavior is identical to the existing async path.On current
main, an ES module graph generates 14 + 5N promises for N modules; so 19 promises for a single module graph (one entry point that doesn’t import anything), 24 promises if that entry point imports one file, 29 promises for a three-module graph and so on.In this PR, only one promise is created regardless of graph size: the low-level V8
module.evaluate()call that happens withinmodule.evaluateSync(), where an immediately-resolved promise is created even for modules that don’t have top-levelawait. But still, it’s only one promise for an entire application, no matter how big the app is.This PR adds a benchmark that focuses on the module loading flow that this PR improves:
The improvement is roughly halving for each doubling of the number of modules, consistent with I/O becoming the dominant cost as the size of the graph grows.