Skip to content

Conversation

@hannojg
Copy link
Contributor

@hannojg hannojg commented Aug 24, 2023

Details

During a performance audit of a large account we noticed, that the isKeyMatch time was taking a lot of time. After further investigation we found that this code is problematic:

function isCollectionKey(key) {
return _.contains(_.values(onyxKeys.COLLECTION), key);
}

We recompute an array again and again and then use includes on an array to check for a match. Do this thousand of times and it becomes slow. Optimising this code reduced the startup time by ~600ms (on a powerful emulator, effects might be stronger on physical device)

Related Issues

GH_LINK: https://expensify.slack.com/archives/C035J5C9FAP/p1692808883217069

Automated Tests

Linked PRs

@hannojg hannojg requested a review from a team as a code owner August 24, 2023 09:42
@melvin-bot melvin-bot bot requested review from dangrous and removed request for a team August 24, 2023 09:42
mountiny
mountiny previously approved these changes Aug 24, 2023
Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com>
Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean simple change, thanks!

@mountiny mountiny merged commit d6cb4fe into Expensify:main Aug 24, 2023
*/
function isCollectionKey(key) {
return _.contains(_.values(onyxKeys.COLLECTION), key);
return onyxCollectionKeyMap.has(key);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants