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

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-botnodejs-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 jasnellJuly 17, 2026 08:50
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecovBot 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 linesPatch %Lines
src/crypto/crypto_kem.cc72.85%10 Missing and 9 partials ⚠️
src/crypto/crypto_kem.h0.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 linesCoverage Δ
src/crypto/crypto_kem.h25.00% <0.00%> (-8.34%)⬇️
src/crypto/crypto_kem.cc74.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.

@panvapanva added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 19, 2026
@panvapanva added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 21, 2026
@nodejs-github-botnodejs-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:mainJul 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
@panvapanva added the backport-open-v26.x Indicate that the PR has an open backport label Jul 21, 2026
aduh95 pushed a commit that referenced this pull request Jul 30, 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: #64553
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
@panvapanva added backported-to-v26.x PRs backported to the v26.x-staging branch. and removed backport-open-v26.x Indicate that the PR has an open backport labels Aug 3, 2026
panva added a commit to panva/node that referenced this pull request Aug 6, 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>
@panvapanva added the backport-open-v24.x Indicate that the PR has an open backport label Aug 6, 2026
aduh95 pushed a commit that referenced this pull request Aug 6, 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: #64553
Backport-PR-URL: #65087
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.backport-open-v24.xIndicate that the PR has an open backportbackported-to-v26.xPRs backported to the v26.x-staging branch.c++Issues and PRs that require attention from people who are familiar with C++.cryptoIssues and PRs related to the crypto subsystem.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@panva@nodejs-github-bot@jasnell@anonrig