Skip to content

crypto: optimize and benchmark key preparation - #65892

Open
panva wants to merge 1 commit into
nodejs:mainfrom
panva:crypto-prepare-key-complete
Open

crypto: optimize and benchmark key preparation#65892
panva wants to merge 1 commit into
nodejs:mainfrom
panva:crypto-prepare-key-complete

Conversation

@panva

@panva panva commented Sep 7, 2026

Copy link
Copy Markdown
Member

Optimize asymmetric key preparation with benchmark and regression coverage for the supported input paths.

Optimize asymmetric key preparation with benchmark and regression
coverage for the supported input paths.

Assisted-by: GitHub Copilot
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Sep 7, 2026
@panva

panva commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

Benchmark GHA (crypto / prepare-asymmetric-key): https://github.com/nodejs/node/actions/runs/34159320684

Results

[!WARNING]
Do not take GHA benchmark results as face value, always confirm them
using a dedicated machine, e.g. Jenkins CI.

Benchmark results:

                                                                                                                   confidence improvement accuracy (*)     (**)    (***)
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='file-direct'                                           1.18 %       ±5.89%   ±7.76%   ±9.96%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='file-passphrase-absent'                         *     -6.77 %       ±5.14%   ±6.78%   ±8.70%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='file-passphrase-string'                               -1.43 %       ±5.45%   ±7.18%   ±9.21%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='pem-passphrase-absent'                        ***    115.99 %       ±7.60%  ±10.03%  ±12.90%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='pem-passphrase-arraybuffer'                   ***    116.22 %       ±8.01%  ±10.57%  ±13.60%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='pem-passphrase-base64'                        ***     50.07 %       ±5.67%   ±7.48%   ±9.60%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='pem-passphrase-buffer'                        ***    146.74 %       ±8.40%  ±11.09%  ±14.27%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='pem-passphrase-empty'                         ***    136.40 %       ±8.36%  ±11.03%  ±14.19%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='pem-passphrase-string'                        ***     85.79 %       ±6.61%   ±8.72%  ±11.21%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-der-pkcs1-bytes'                      ***    115.19 %       ±6.92%   ±9.13%  ±11.74%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-der-pkcs8-base64'                     ***     17.76 %       ±8.63%  ±11.38%  ±14.60%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-der-pkcs8-bytes'                      ***    117.09 %       ±7.21%   ±9.51%  ±12.24%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-der-pkcs8-hex'                                 3.80 %       ±4.77%   ±6.28%   ±8.06%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-der-sec1-bytes'                       ***    118.18 %       ±7.49%   ±9.89%  ±12.72%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-jwk'                                  ***    -18.45 %       ±3.78%   ±4.99%   ±6.40%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-keyobject-wrapped'                             0.00 %       ±4.32%   ±5.69%   ±7.30%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-keyobject'                            ***     57.39 %       ±7.21%   ±9.51%  ±12.21%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-pem-arraybuffer-wrapped'              ***     33.63 %       ±5.08%   ±6.70%   ±8.60%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-pem-arraybuffer'                      ***     35.69 %       ±5.28%   ±6.96%   ±8.93%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-pem-buffer-wrapped'                   ***    117.15 %       ±7.90%  ±10.43%  ±13.41%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-pem-buffer'                           ***   5375.98 %     ±208.86% ±276.13% ±355.91%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-pem-pkcs8-bytes'                      ***    113.68 %       ±7.37%   ±9.74%  ±12.52%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-pem-string-wrapped'                   ***     24.07 %      ±10.33%  ±13.62%  ±17.49%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='private-pem-string'                           ***     29.82 %      ±12.65%  ±16.68%  ±21.42%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='provider-direct'                                       3.38 %       ±4.78%   ±6.30%   ±8.09%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='provider-passphrase-absent-properties'        ***    -17.23 %       ±4.03%   ±5.31%   ±6.81%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='provider-passphrase-absent'                   ***    -16.22 %       ±4.08%   ±5.38%   ±6.90%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='provider-passphrase-arraybuffer'                       1.43 %       ±4.65%   ±6.13%   ±7.86%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='provider-passphrase-base64'                            1.17 %       ±4.41%   ±5.82%   ±7.46%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='provider-passphrase-buffer'                            1.25 %       ±4.47%   ±5.90%   ±7.57%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='provider-passphrase-empty'                             2.87 %       ±4.50%   ±5.93%   ±7.62%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='provider-passphrase-string'                            0.61 %       ±4.52%   ±5.96%   ±7.65%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='raw-private-ec-arraybuffer'                   ***     18.35 %       ±4.80%   ±6.33%   ±8.12%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='raw-private-ec-buffer'                        ***     90.59 %       ±6.81%   ±8.99%  ±11.55%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='raw-private-ed25519-buffer'                   ***     91.35 %       ±6.72%   ±8.87%  ±11.40%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-private' input='raw-seed-ml-dsa-44-buffer'                    ***     96.52 %       ±6.66%   ±8.79%  ±11.30%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-public' input='private-keyobject-wrapped'                             -0.62 %       ±4.22%   ±5.56%   ±7.14%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-public' input='private-keyobject'                             ***     58.39 %       ±7.63%  ±10.06%  ±12.92%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-public' input='public-der-pkcs1-bytes'                        ***    118.70 %       ±7.60%  ±10.03%  ±12.90%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-public' input='public-der-spki-bytes'                         ***    121.70 %       ±7.46%   ±9.84%  ±12.66%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-public' input='public-keyobject-wrapped'                              -2.36 %       ±4.44%   ±5.85%   ±7.51%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-public' input='public-keyobject'                              ***     54.63 %       ±8.33%  ±10.99%  ±14.11%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-public' input='public-pem-buffer-wrapped'                     ***    119.39 %       ±7.29%   ±9.62%  ±12.37%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-public' input='raw-public-ec-buffer'                          ***     94.23 %       ±6.70%   ±8.84%  ±11.36%
crypto/prepare-asymmetric-key.js n=1000000 context='consume-public' input='raw-public-ed25519-buffer'                     ***     95.13 %       ±6.85%   ±9.04%  ±11.62%
crypto/prepare-asymmetric-key.js n=1000000 context='create-public' input='private-keyobject-wrapped'                              -1.43 %       ±4.22%   ±5.57%   ±7.14%
crypto/prepare-asymmetric-key.js n=1000000 context='create-public' input='private-keyobject'                              ***     57.26 %       ±7.69%  ±10.14%  ±13.02%

Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case, there are 47 comparisons, you can thus
expect the following amount of false-positive results:
  2.35 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.47 false positives, when considering a   1% risk acceptance (**, ***),
  0.05 false positives, when considering a 0.1% risk acceptance (***)

[!WARNING]
Do not take GHA benchmark results as face value, always confirm them
using a dedicated machine, e.g. Jenkins CI.

@panva panva added the performance Issues and PRs related to the performance of Node.js. label Sep 7, 2026
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.17%. Comparing base (b4c83f5) to head (4f25ec9).
⚠️ Report is 33 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #65892   +/-   ##
=======================================
  Coverage   90.16%   90.17%           
=======================================
  Files         771      771           
  Lines      265094   265123   +29     
  Branches    50367    50367           
=======================================
+ Hits       239035   239067   +32     
- Misses      17000    17006    +6     
+ Partials     9059     9050    -9     
Files with missing lines Coverage Δ
lib/internal/crypto/keys.js 98.15% <100.00%> (+0.03%) ⬆️

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

@meixg meixg added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 8, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 8, 2026
@nodejs-github-bot

This comment has been minimized.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@panva panva added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Sep 8, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@panva panva added the commit-queue PRs queued for automated landing through the Commit Queue. label Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue PRs queued for automated landing through the Commit Queue. crypto Issues and PRs related to the crypto subsystem. 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.

5 participants