From 48e7ea0b9ce74d603ef98e16ccb5b1060546a77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Thu, 24 Aug 2023 11:38:58 +0200 Subject: [PATCH 1/2] Use collection key value map instead of recomputing everytime --- lib/Onyx.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index 27f49aec2..cd4ce3ab0 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -27,8 +27,8 @@ let lastConnectionID = 0; // Holds a mapping of all the react components that want their state subscribed to a store key const callbackToStateMapping = {}; -// Stores all of the keys that Onyx can use. Must be defined in init(). -let onyxKeys = {}; +// Keeps a copy of the values of the onyx collection keys as a a map for faster lookups +let onyxCollectionKeyMap = {}; // Holds a list of keys that have been directly subscribed to or recently modified from least to most recent let recentlyAccessedKeys = []; @@ -141,7 +141,7 @@ function getAllKeys() { * @returns {Boolean} */ function isCollectionKey(key) { - return _.contains(_.values(onyxKeys.COLLECTION), key); + return onyxCollectionKeyMap.has(key); } /** @@ -1392,8 +1392,13 @@ function init({ cache.setRecentKeysLimit(maxCachedKeysCount); } - // Let Onyx know about all of our keys - onyxKeys = keys; + // We need the value of the collection keys later for checking if a + // key is a collection. We store it in a map for faster lookup. + const collectionValues = _.values(keys.COLLECTION); + onyxCollectionKeyMap = _.reduce(collectionValues, (acc, val) => { + acc.set(val, true); + return acc; + }, new Map()); // Set our default key states to use when initializing and clearing Onyx data defaultKeyStates = initialKeyStates; From e7e874ebf6af32aa454850e993da9394b0ccf205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Thu, 24 Aug 2023 11:48:51 +0200 Subject: [PATCH 2/2] Update lib/Onyx.js Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- lib/Onyx.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index cd4ce3ab0..4b210f946 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -27,7 +27,7 @@ let lastConnectionID = 0; // Holds a mapping of all the react components that want their state subscribed to a store key const callbackToStateMapping = {}; -// Keeps a copy of the values of the onyx collection keys as a a map for faster lookups +// Keeps a copy of the values of the onyx collection keys as a map for faster lookups let onyxCollectionKeyMap = {}; // Holds a list of keys that have been directly subscribed to or recently modified from least to most recent