Skip to content

src: avoid redundant KEM encapsulation copies#64553

Open
panva wants to merge 1 commit into
nodejs:mainfrom
panva:kem-perf
Open

src: avoid redundant KEM encapsulation copies#64553
panva wants to merge 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 6 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.

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

Labels

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.

2 participants