module: do less CJS module loader initialization at run time
This patch:
- Builds the set of modules that can be required by users with/without the
node:
prefix at snapshot building time. We only modify it when--expose-internals
or the flag for experimental wasi module is true but the default set is now in the snapshot. At run time the CJS module loader only creates a frozen array out of it. -
BuiltinModule.canBeRequiredWithoutScheme()
is now enough to determine if an id can be required withoutnode:
without an additional call toBuiltinModule.canBeRequiredByUsers()
- Replace the pending-to-deprecate methods on
Module
with an internal implementation that only queries the CLI flags when being invoked. So we can install these methods in the snapshot.
Local benchmark numbers:
confidence improvement accuracy (*) (**) (***)
misc/startup.js count=30 mode='process' script='benchmark/fixtures/require-builtins' 0.32 % ±0.40% ±0.53% ±0.69%
misc/startup.js count=30 mode='process' script='test/fixtures/semicolon' *** 1.27 % ±0.57% ±0.76% ±0.99%
misc/startup.js count=30 mode='worker' script='benchmark/fixtures/require-builtins' -0.40 % ±0.44% ±0.59% ±0.77%
misc/startup.js count=30 mode='worker' script='test/fixtures/semicolon' 0.23 % ±0.54% ±0.72% ±0.94%