Skip to content

build,src,crypto: improve startup performance - #65549

Draft
avivkeller wants to merge 3 commits into
nodejs:mainfrom
avivkeller:startup-perf
Draft

build,src,crypto: improve startup performance#65549
avivkeller wants to merge 3 commits into
nodejs:mainfrom
avivkeller:startup-perf

Conversation

@avivkeller

@avivkeller avivkeller commented Aug 25, 2026

Copy link
Copy Markdown
Member

(I can split these into separate PRs if needed, but I figured a single PR with separate commits would be sufficient since the changes are related: ce94bb8 made me think about 2dffdbf, which in turn relied on a1ba046.)

In order of commits, this:

  • Avoids atexit(), since it's slow (dladdr() performs an expensive linear scan of the executable's symbol table)
  • Lazily-loads well-known Crypto ciphers
  • Once again avoids atexit(), this time in OpenSSL.

On my mac, improves startups by ~15%:

$ hyperfine --warmup 25 --runs 100 'node -e "0"' './node -e "0"'

Benchmark 1: node -e "0"
  Time (mean ± σ):      39.3 ms ±   2.2 ms    [User: 31.6 ms, System: 6.4 ms]
  Range (min … max):    36.5 ms …  55.0 ms    100 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: ./node -e "0"
  Time (mean ± σ):      34.2 ms ±   2.1 ms    [User: 26.4 ms, System: 6.4 ms]
  Range (min … max):    32.4 ms …  49.3 ms    100 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Summary
  ./node -e "0" ran
    1.15 ± 0.10 times faster than node -e "0"

@avivkeller avivkeller added performance Issues and PRs related to the performance of Node.js. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. labels Aug 25, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/gyp
  • @nodejs/security-wg
  • @nodejs/startup
  • @nodejs/v8-update

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Aug 25, 2026
atexit() calls dladdr() to find the image that
owns the callback. dladdr() performs an expensive
linear scan of the executable's symbol
table, so we now avoid it entirely.

Signed-off-by: Aviv Keller <me@aviv.sh>
The Cipher::AES_* and Cipher::CHACHA20_POLY1305
constants were initialized by static initializers
while the executable is still being loaded.

Lazily-load them now, so they are only init'd on
first use.

Signed-off-by: Aviv Keller <me@aviv.sh>
Now that crypto no longer initializes OpenSSL
from a static initalizer (see previous commit),
nothing requires OpenSSL to be torn down at process
exit. As mentioned in an earlier commit, `atexit`
is expensive, so we now once again avoid it.

Signed-off-by: Aviv Keller <me@aviv.sh>
@jasnell

jasnell commented Aug 25, 2026

Copy link
Copy Markdown
Member

Please separate out the crypto ones into a separate PR and coordinate with @panva ... he has some other edits that may conflict.

@panva

panva commented Aug 25, 2026

Copy link
Copy Markdown
Member

a1ba046 conflicts with #65484, please hold off updating crypto until those changes land.

@avivkeller
avivkeller marked this pull request as draft August 25, 2026 19:07
@panva

panva commented Aug 25, 2026

Copy link
Copy Markdown
Member

Thank you

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.11%. Comparing base (ce40aa2) to head (2dffdbf).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/crypto/crypto_context.cc 77.77% 0 Missing and 2 partials ⚠️
src/node.cc 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65549      +/-   ##
==========================================
- Coverage   90.14%   90.11%   -0.03%     
==========================================
  Files         751      751              
  Lines      253635   253645      +10     
  Branches    47793    47786       -7     
==========================================
- Hits       228632   228574      -58     
- Misses      16249    16315      +66     
- Partials     8754     8756       +2     
Files with missing lines Coverage Δ
src/crypto/crypto_aes.h 33.33% <ø> (ø)
src/crypto/crypto_chacha20_poly1305.cc 52.27% <100.00%> (ø)
src/node.cc 76.58% <75.00%> (-0.07%) ⬇️
src/crypto/crypto_context.cc 71.75% <77.77%> (+0.08%) ⬆️

... and 38 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. performance Issues and PRs related to the performance of Node.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants