diff options
author | James M Snell <jasnell@gmail.com> | 2016-06-08 08:18:26 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-06-21 10:03:08 -0700 |
commit | 6be73feaeb31dbcc1547da648341c0b6f0d2d2bb (patch) | |
tree | a03e867b1d8f25af8183bd2741765c45d9a8db2b /lib/crypto.js | |
parent | 58a241d53790aee5dd6327543fc9849bd21fb9a7 (diff) | |
download | android-node-v8-6be73feaeb31dbcc1547da648341c0b6f0d2d2bb.tar.gz android-node-v8-6be73feaeb31dbcc1547da648341c0b6f0d2d2bb.tar.bz2 android-node-v8-6be73feaeb31dbcc1547da648341c0b6f0d2d2bb.zip |
crypto,tls: perf improvements for crypto and tls getCiphers
Improve performance of crypto.getCiphers, getHashes, getCurves
and tls.getCiphers by consolidating filterDuplicates logic, adding
caching of output, and streamlining filterDuplicates implementation.
Benchmarks:
crypto.getCiphers n=1 v6.2.1 = 2559.3, new = 15890 ...... -83.89%
crypto.getCiphers n=5000 v6.2.1 = 3516.3, new = 24203000 ... -99.99%
tls.getCiphers n=1 v6.2.1 = 3405.3, new = 14877 ...... -77.11%
tls.getCiphers n=5000 v6.2.1 = 6074.4, new = 24202000 ... -99.97%
PR-URL: https://github.com/nodejs/node/pull/7225
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'lib/crypto.js')
-rw-r--r-- | lib/crypto.js | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/lib/crypto.js b/lib/crypto.js index 4bce371701..9ffff06f7f 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -632,41 +632,23 @@ exports.randomBytes = exports.pseudoRandomBytes = randomBytes; exports.rng = exports.prng = randomBytes; -exports.getCiphers = function() { - return filterDuplicates(getCiphers()); -}; - - -exports.getHashes = function() { - return filterDuplicates(getHashes()); -}; +exports.getCiphers = internalUtil.cachedResult(() => { + return internalUtil.filterDuplicateStrings(getCiphers()); +}); +exports.getHashes = internalUtil.cachedResult(() => { + return internalUtil.filterDuplicateStrings(getHashes()); +}); -exports.getCurves = function() { - return filterDuplicates(getCurves()); -}; +exports.getCurves = internalUtil.cachedResult(() => { + return internalUtil.filterDuplicateStrings(getCurves()); +}); Object.defineProperty(exports, 'fips', { get: getFipsCrypto, set: setFipsCrypto }); -function filterDuplicates(names) { - // Drop all-caps names in favor of their lowercase aliases, - // for example, 'sha1' instead of 'SHA1'. - var ctx = {}; - names.forEach(function(name) { - var key = name; - if (/^[0-9A-Z\-]+$/.test(key)) key = key.toLowerCase(); - if (!ctx.hasOwnProperty(key) || ctx[key] < name) - ctx[key] = name; - }); - - return Object.getOwnPropertyNames(ctx).map(function(key) { - return ctx[key]; - }).sort(); -} - // Legacy API Object.defineProperty(exports, 'createCredentials', { configurable: true, |