Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit use of unnecessary spread for performance #165

Merged
merged 1 commit into from
Aug 4, 2022

Conversation

marcaaron
Copy link
Contributor

Details

@luacmartins found some spread calls that were taking a long time in this thread.

Looking at the code and it seems like there is no clear reason to use the spread operator over simply building an object up one key at a time. When objects become large it is more and more expensive to do the spread as each iteration creates a copy.

Related Issues

https://github.com/Expensify/Expensify/issues/219425

Automated Tests

Linked PRs

Let's add these changes into this PR

@marcaaron marcaaron self-assigned this Aug 4, 2022
@marcaaron marcaaron requested a review from a team as a code owner August 4, 2022 01:19
@melvin-bot melvin-bot bot requested review from TomatoToaster and removed request for a team August 4, 2022 01:20
Copy link
Contributor

@luacmartins luacmartins left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the PR!

Comment on lines +235 to +238

// eslint-disable-next-line no-param-reassign
prev[curr] = cachedValue;
return prev;
Copy link
Member

Choose a reason for hiding this comment

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

It could have a side effect theoretically. Because we are preserving the same ref to prev object, this operation will update the value in each reference. So I think the previous cache values will update in storageMap. I haven't tested it so it is just an assumption.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm maybe I'm missing something but the reference to prev seems to be the empty object declared as the reducer accumulator and shouldn't be updated anywhere else since it's declared in the reducer call, no?

Copy link
Member

Choose a reason for hiding this comment

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

Lol, totally missed that.

@luacmartins
Copy link
Contributor

Cool! I'll merge this to help solve the performance regression asap

@luacmartins luacmartins merged commit 096418c into main Aug 4, 2022
@luacmartins
Copy link
Contributor

luacmartins commented Aug 4, 2022

@marcaaron I'm already updating Onyx as part of https://github.com/Expensify/App/pull/10051/files, so I can just bump it up to this version

@marcaaron
Copy link
Contributor Author

Cool I've also added it in this Expensify/App#10239 which might be able to get deployed sooner

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