Skip to content

src: avoid redundant KEM encapsulation copies#64553

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
panva:kem-perf
Jul 21, 2026
Merged

src: avoid redundant KEM encapsulation copies#64553
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
panva:kem-perf

Conversation

@panva

@panva panva commented Jul 17, 2026

Copy link
Copy Markdown
Member

KEM encapsulation produces separate ciphertext and shared-secret allocations. The existing DeriveBitsJob path packs both values into an intermediate buffer, then copies them again into separate buffers.

Instead, this uses a dedicated KEMEncapsulateJob to retain both outputs across the worker boundary and convert each directly through ByteSource. This removes the intermediate allocation and at least one complete round of copies.

KEM encapsulation produces separate ciphertext and shared-secret
allocations. The existing DeriveBitsJob path packs both values into an
intermediate buffer, then copies them again into separate buffers.

Instead, this uses a dedicated KEMEncapsulateJob to retain both outputs
across the worker boundary and convert each directly through ByteSource.
This removes the intermediate allocation and at least one complete round
of copies.

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 c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Jul 17, 2026
@panva
panva requested a review from jasnell July 17, 2026 08:50
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.83099% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.23%. Comparing base (a27fe21) to head (7b86953).
⚠️ Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
src/crypto/crypto_kem.cc 72.85% 10 Missing and 9 partials ⚠️
src/crypto/crypto_kem.h 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64553      +/-   ##
==========================================
- Coverage   90.24%   90.23%   -0.02%     
==========================================
  Files         739      739              
  Lines      241698   241709      +11     
  Branches    45556    45551       -5     
==========================================
- Hits       218129   218113      -16     
- Misses      15103    15119      +16     
- Partials     8466     8477      +11     
Files with missing lines Coverage Δ
src/crypto/crypto_kem.h 25.00% <0.00%> (-8.34%) ⬇️
src/crypto/crypto_kem.cc 74.84% <72.85%> (-5.70%) ⬇️

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

@panva panva added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 19, 2026
@panva panva added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 21, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 21, 2026
@nodejs-github-bot
nodejs-github-bot merged commit db3a8d8 into nodejs:main Jul 21, 2026
83 of 84 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in db3a8d8

@panva
panva deleted the kem-perf branch July 21, 2026 15:49
@panva panva added the backport-open-v26.x Indicate that the PR has an open backport label Jul 21, 2026
aduh95 pushed a commit to panva/node that referenced this pull request Jul 21, 2026
KEM encapsulation produces separate ciphertext and shared-secret
allocations. The existing DeriveBitsJob path packs both values into an
intermediate buffer, then copies them again into separate buffers.

Instead, this uses a dedicated KEMEncapsulateJob to retain both outputs
across the worker boundary and convert each directly through ByteSource.
This removes the intermediate allocation and at least one complete round
of copies.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: nodejs#64553
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backport-open-v26.x Indicate that the PR has an open backport c++ Issues and PRs that require attention from people who are familiar with C++. 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.

4 participants