Repository navigation
Conversation
node.exe imports crypt32, dbghelp, iphlpapi, ole32, shell32, userenv and winmm, so every process loads them, and the DLLs they depend on, at start-up. They are only needed by less common code paths such as the system certificate store, network interface queries and diagnostic reports. Delay-load them so they are loaded on first use. On Windows 11 this takes `node -e 0` from 35 to 26 loaded images and saves about 2.5 ms per process. Signed-off-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
Collaborator
|
Review requested:
|
Contributor
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. |
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.
Summary
Delay-load seven Windows DLLs that are currently linked as regular imports, avoiding the cost of loading them during process startup unless they are actually needed.
This reduces startup time for some short-lived Node.js processes without changing when or how the underlying functionality is used.
Motivation
On Windows, DLLs listed in an executable's import table are loaded during process initialization even if the process never calls into them.
Node.js imports several DLLs that are rarely needed by short-lived processes, but their loading cost is paid on every invocation.
This is particularly relevant for workloads that frequently spawn Node.js processes, such as package managers, build tools, and AI coding agents.
Changes
crypt32,dbghelp,iphlpapi,ole32,shell32,userenvandwinmm) for delay-loading in the build configurationPerformance
Measured on Windows 11 (i9-14900K), same build with and without the change, 100 interleaved runs each:
node -e 0node --versionApproximately 2.6 ms faster startup (~6% for
node -e 0). The number of DLLs loaded at startup goes from 35 to 26.The improvement is most relevant to short-lived processes, where initialization represents a significant portion of total execution time.
Testing
About 1,400 Node.js tests (crypto, tls, https, net, dns, os, fs, child processes, workers, reports and others) produced the same results with and without the change.
Additional context
This change is independent of a complementary libuv change, libuv/libuv#5389, that starts the Windows console resize watcher only when it is needed. Once Node.js picks up that change,
user32.dllcan be added to this list as well, which saves about another 5-8 ms per process.I used GitHub Copilot to help investigate and measure this change. I reviewed the change and verified the results myself.