crypto: optimize SubtleCrypto dispatch hot paths#62756
Open
panva wants to merge 6 commits intonodejs:mainfrom
Open
crypto: optimize SubtleCrypto dispatch hot paths#62756panva wants to merge 6 commits intonodejs:mainfrom
panva wants to merge 6 commits intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
c23467e to
62dec56
Compare
62dec56 to
8cfb8ef
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62756 +/- ##
==========================================
- Coverage 89.69% 89.67% -0.03%
==========================================
Files 706 706
Lines 218127 218202 +75
Branches 41734 41745 +11
==========================================
+ Hits 195651 195664 +13
- Misses 14400 14455 +55
- Partials 8076 8083 +7
🚀 New features to boost your workflow:
|
Exercise `normalizeAlgorithm`, `converters.AlgorithmIdentifier`, `createDictionaryConverter` (with/without `[EnforceRange]` integers and `ensureSHA` validators), and `converters.AeadParams`. Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Replace O(n) for...in loop with case-insensitive
StringPrototypeToUpperCase comparisons per algorithm
with O(1) SafeMap lookup. The map is pre-built at module
init alongside kSupportedAlgorithms.
Hoist the opts object literal used in normalizeAlgorithm
to module level to avoid allocating identical
{ prefix, context } objects on every call.
Pre-compute ObjectKeys() for simpleAlgorithmDictionaries
entries at module init to avoid allocating a new keys
array on every normalizeAlgorithm call.
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
8cfb8ef to
cc1451b
Compare
Replace SafeArrayIterator with index-based loop in the inner function
returned by createDictionaryConverter, avoiding iterator object creation
on every dictionary conversion.
Replace object spread (`{ ...opts, context }`) with explicit property
assignment when passing opts to member converters. This avoids
allocating a full spread copy per dictionary member.
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Use a direct `typeof` check in `converters.object` and `converters.AlgorithmIdentifier` instead of the generic `type()` helper, which returned an intermediate 'Object' / 'Null' / ... string tag. Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Simplify the generated dictionary converter's per-call work: classify V with `typeof` instead of `type()`, hoist `opts.prefix`/`opts.context` and `allMembers.length` out of the loop, and initialize `allMembers` with direct index assignment instead of `ArrayPrototypePush`. Also drops the now-unused `type()` helper. Signed-off-by: Filip Skokan <panva.ip@gmail.com>
The inline `[EnforceRange] unsigned short/long/octet` wrappers spread the per-member opts object into a new one solely to set `enforceRange: true`. Replace the 18 inline wrappers with shared helpers that mutate the caller-supplied opts in place. Signed-off-by: Filip Skokan <panva.ip@gmail.com>
cc1451b to
f98babc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This improves several hot paths in Web Cryptography.
Per-commit gains (each vs its parent)
crypto: optimize normalizeAlgorithm hot path
for...inloop with an O(1)SafeMaplookup pre-built at module init.{ prefix, context }options object to module scope.ObjectKeys()forsimpleAlgorithmDictionariesentries at module init.normalizeAlgorithm-stringnormalizeAlgorithm-dictcrypto: reduce allocations in WebIDL dictionary converter
SafeArrayIteratorwith an index-based loop in the inner function returned bycreateDictionaryConverter.{ __proto__: null, ...opts, context }with explicit property assignment when passing opts to member converters.webidl-dictwebidl-dict-nullcrypto: skip string tag allocation in AlgorithmIdentifier fast path
typeofcheck inconverters.objectandconverters.AlgorithmIdentifierinstead of the generictype()helper, which returned an intermediate'Object' / 'Null' / ...string tag.webidl-algorithm-identifier-stringwebidl-algorithm-identifier-objectcrypto: streamline WebIDL dictionary converter hot loop
Vwithtypeofinstead oftype().opts.prefix/opts.contextandallMembers.lengthout of the loop; initializeallMemberswith direct index assignment.type()helper.webidl-dictnormalizeAlgorithm-dictwebidl-dict-enforce-rangecrypto: reuse enforceRange option object for WebIDL integer members
[EnforceRange] unsigned short/long/octetwrappers spread the per-member opts object into a new one solely to setenforceRange: true. Replace the 18 inline wrappers with shared helpers that mutate the caller-supplied opts in place.webidl-dict-enforce-rangeCumulative
normalizeAlgorithm-stringnormalizeAlgorithm-dictwebidl-dictwebidl-dict-nullwebidl-algorithm-identifier-stringwebidl-algorithm-identifier-objectwebidl-dict-enforce-rangeA benchmark is added in the first commit (
benchmark/crypto/webcrypto-webidl.js) coveringnormalizeAlgorithm,converters.AlgorithmIdentifier,createDictionaryConverter(with/without[EnforceRange]integer members and with a null/undefined required-member fast path), andconverters.AeadParams.