From f3b3726b628d4b14a62282914f396e1b52ca4715 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Tue, 5 Jun 2018 13:12:31 +0200 Subject: [PATCH 1/7] Improved performance for getTop --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index e443cab..06e697b 100644 --- a/index.js +++ b/index.js @@ -45,10 +45,10 @@ function get(data, key) { * Get the top data */ function getTop(data) { - if (!data.parent) { - return data; + while (data.parent) { + data = data.parent } - return getTop(data.parent); + return data } let currentId = 0; From c83d3d08fbefbe32c4f6438be522e3e7ac01dd0e Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Tue, 5 Jun 2018 15:48:50 +0200 Subject: [PATCH 2/7] Flagged linkedTop param in JSDoc on set to be optional --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 06e697b..008bba3 100644 --- a/index.js +++ b/index.js @@ -136,7 +136,7 @@ exports.disableLinkedTop = () => { * Set the key/value for this score * @param {String} key The key of value * @param {String} value The value - * @param {Boolean} linkedTop The value linked to top + * @param {Boolean} [linkedTop] The value linked to top * @returns {Boolean} if success, will return true, otherwise false */ exports.set = function setValue(key, value, linkedTop) { From c2635d1e05955c1575061bd6b7cfdd3af123584b Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Tue, 5 Jun 2018 15:55:52 +0200 Subject: [PATCH 3/7] Fix type of value parameter on set function through JSDoc --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 008bba3..d477890 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,6 @@ const nano = require('nano-seconds'); const util = require('util'); const fs = require('fs'); - const map = new Map(); const enabledDebug = process.env.DEBUG === 'als'; @@ -135,7 +134,7 @@ exports.disableLinkedTop = () => { /** * Set the key/value for this score * @param {String} key The key of value - * @param {String} value The value + * @param {any} value The value * @param {Boolean} [linkedTop] The value linked to top * @returns {Boolean} if success, will return true, otherwise false */ From 1166cbb550a628f0c2b3e9e442792e3fcd47bddb Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Tue, 5 Jun 2018 16:01:46 +0200 Subject: [PATCH 4/7] Higher performance due to skipping debug string concatenation unless actually in debug mode --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index d477890..11878e2 100644 --- a/index.js +++ b/index.js @@ -65,7 +65,7 @@ const hooks = asyncHooks.createHook({ data.parent = parent; } } - debug(`${id}(${type}) init by ${triggerId}`); + debug('%d($s) init by %d', id, type, triggerId); map.set(id, data); }, /** @@ -81,7 +81,7 @@ const hooks = asyncHooks.createHook({ if (!map.has(id)) { return; } - debug(`destroy ${id}`); + debug('destroy %d', id); map.delete(id); }, }); From b840fe7394993bb4bfc5ffb0a6b7846de735bf59 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Tue, 5 Jun 2018 16:05:43 +0200 Subject: [PATCH 5/7] Updated misses debeg statements to higher performance approach --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 11878e2..354b89b 100644 --- a/index.js +++ b/index.js @@ -144,7 +144,7 @@ exports.set = function setValue(key, value, linkedTop) { throw new Error('can\'t set created and parent'); } const id = getCurrentId(); - debug(`set ${key}:${value} to ${id}`); + debug('set %s:$j to %d', key, value, id); let data = map.get(id); /* istanbul ignore if */ if (!data) { @@ -168,7 +168,7 @@ exports.set = function setValue(key, value, linkedTop) { exports.get = function getValue(key) { const data = map.get(getCurrentId()); const value = get(data, key); - debug(`get ${key}:${value} from ${currentId}`); + debug('get $s:%j from %d', key, value, currentId); return value; }; From a8c51850db83a3ce20dd10d09a348954f270fda2 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Tue, 5 Jun 2018 16:10:45 +0200 Subject: [PATCH 6/7] Fixed typo --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 354b89b..7f71916 100644 --- a/index.js +++ b/index.js @@ -65,7 +65,7 @@ const hooks = asyncHooks.createHook({ data.parent = parent; } } - debug('%d($s) init by %d', id, type, triggerId); + debug('%d(%s) init by %d', id, type, triggerId); map.set(id, data); }, /** From 6542da98b61991491bc8fcc956e5e4c51964561b Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Tue, 5 Jun 2018 16:12:54 +0200 Subject: [PATCH 7/7] And 2 more typos --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7f71916..0cb4fbe 100644 --- a/index.js +++ b/index.js @@ -144,7 +144,7 @@ exports.set = function setValue(key, value, linkedTop) { throw new Error('can\'t set created and parent'); } const id = getCurrentId(); - debug('set %s:$j to %d', key, value, id); + debug('set %s:%j to %d', key, value, id); let data = map.get(id); /* istanbul ignore if */ if (!data) { @@ -168,7 +168,7 @@ exports.set = function setValue(key, value, linkedTop) { exports.get = function getValue(key) { const data = map.get(getCurrentId()); const value = get(data, key); - debug('get $s:%j from %d', key, value, currentId); + debug('get %s:%j from %d', key, value, currentId); return value; };