Skip to content

lib: avoid repeat internal receiver checks - #65910

Open
panva wants to merge 1 commit into
nodejs:mainfrom
panva:crypto-key-slot-access
Open

lib: avoid repeat internal receiver checks#65910
panva wants to merge 1 commit into
nodejs:mainfrom
panva:crypto-key-slot-access

Conversation

@panva

@panva panva commented Sep 8, 2026

Copy link
Copy Markdown
Member

Let internal helpers access the private cache directly to avoid repeating receiver checks since CryptoKey webidl now does the brand check.

Update test coverage to ensure future public getters or methods don't forget the brand check.

Refs: #65846

Let internal helpers access the private cache directly to avoid
repeating receiver checks.

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

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto

@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 8, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Benchmark GHA (crypto / class-methods): https://github.com/nodejs/node/actions/runs/34225714923

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/class-methods.js n=100000 operation='CryptoKey-algorithm-first'                       -0.53 %       ±6.54%  ±8.62% ±11.06%
crypto/class-methods.js n=100000 operation='CryptoKey-extractable-first'                      0.18 %       ±6.24%  ±8.23% ±10.56%
crypto/class-methods.js n=100000 operation='CryptoKey-type-first'                             0.32 %       ±6.18%  ±8.14% ±10.45%
crypto/class-methods.js n=100000 operation='CryptoKey-usages-first'                           0.22 %       ±6.46%  ±8.51% ±10.92%
crypto/class-methods.js n=100000 operation='KeyObject-symmetricKeySize-first'                -1.45 %       ±5.81%  ±7.65%  ±9.82%
crypto/class-methods.js n=100000 operation='KeyObject-type-first'                            -0.01 %       ±5.81%  ±7.66%  ±9.83%
crypto/class-methods.js n=1000000 operation='Cipheriv-update'                                 0.48 %       ±7.94% ±10.47% ±13.44%
crypto/class-methods.js n=1000000 operation='Decipheriv-update'                               1.03 %       ±8.15% ±10.74% ±13.78%
crypto/class-methods.js n=1000000 operation='X509Certificate-checkHost'                      -0.80 %       ±7.21%  ±9.51% ±12.20%
crypto/class-methods.js n=100000000 operation='CryptoKey-type'                         *      6.98 %       ±5.36%  ±7.06%  ±9.07%
crypto/class-methods.js n=100000000 operation='KeyObject-type'                                0.76 %       ±5.33%  ±7.03%  ±9.02%
crypto/class-methods.js n=100000000 operation='X509Certificate-publicKey'                    -1.11 %       ±5.52%  ±7.28%  ±9.34%
crypto/class-methods.js n=100000000 operation='X509Certificate-subject'                       0.56 %       ±5.72%  ±7.54%  ±9.68%
crypto/class-methods.js n=200000 operation='CryptoKey-toKeyObject'                            1.83 %       ±5.32%  ±7.01%  ±9.00%
crypto/class-methods.js n=200000 operation='DiffieHellman-getGenerator'                       0.57 %       ±3.10%  ±4.08%  ±5.24%
crypto/class-methods.js n=2000000 operation='DiffieHellmanGroup-getGenerator'                 3.01 %      ±10.41% ±13.73% ±17.61%
crypto/class-methods.js n=2000000 operation='ECDH-getPrivateKey'                              2.15 %       ±8.18% ±10.79% ±13.84%
crypto/class-methods.js n=2000000 operation='KeyObject-equals'                               -0.85 %       ±3.06%  ±4.04%  ±5.18%
crypto/class-methods.js n=5000 operation='X509Certificate-publicKey-first'                   -1.42 %       ±8.12% ±10.70% ±13.73%
crypto/class-methods.js n=5000 operation='X509Certificate-subject-first'                     -1.55 %       ±7.94% ±10.47% ±13.43%
crypto/class-methods.js n=5000000 operation='Hash-update'                                    -0.44 %       ±3.73%  ±4.91%  ±6.30%
crypto/class-methods.js n=5000000 operation='Hmac-update'                                    -0.99 %       ±3.91%  ±5.16%  ±6.62%
crypto/class-methods.js n=5000000 operation='Sign-update'                                    -0.36 %       ±3.98%  ±5.25%  ±6.74%
crypto/class-methods.js n=5000000 operation='Verify-update'                                  -0.51 %       ±3.98%  ±5.25%  ±6.74%

Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case, there are 24 comparisons, you can thus
expect the following amount of false-positive results:
  1.20 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.24 false positives, when considering a   1% risk acceptance (**, ***),
  0.02 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.

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.17%. Comparing base (70458d5) to head (e6f8905).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65910      +/-   ##
==========================================
- Coverage   90.18%   90.17%   -0.01%     
==========================================
  Files         771      771              
  Lines      265103   265072      -31     
  Branches    50353    50348       -5     
==========================================
- Hits       239082   239039      -43     
- Misses      16968    16998      +30     
+ Partials     9053     9035      -18     
Files with missing lines Coverage Δ
lib/internal/crypto/keys.js 98.20% <100.00%> (+0.07%) ⬆️

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

crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants