-
Notifications
You must be signed in to change notification settings - Fork 89
Don't recreate iterator every time #363
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
Conversation
francoisl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, just one small question to clarify
| delete this.storageMap[temp[i]]; | ||
| this.recentKeys.delete(temp[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why not use drop() here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to remove key from storageKeys as that's used for getAllKeys. We don't remove the key from the db only from cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
danieldoglas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
mountiny
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, thanks!
lib/OnyxCache.js
Outdated
| removeLeastRecentlyUsedKeys() { | ||
| while (this.recentKeys.size > this.maxRecentKeysSize) { | ||
| const iterator = this.recentKeys.values(); | ||
| let toRemove = this.recentKeys.size - this.maxRecentKeysSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let toRemove = this.recentKeys.size - this.maxRecentKeysSize; | |
| let numKeysToRemove = this.recentKeys.size - this.maxRecentKeysSize; |
lib/OnyxCache.js
Outdated
| const temp = []; | ||
| while (toRemove > 0) { | ||
| const value = iterator.next().value; | ||
| if (value !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If value is undefined, should we break?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it shouldn't every be undefined. I will remove it.
| toRemove--; | ||
| } | ||
|
|
||
| for (let i = 0; i < temp.length; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why aggregate temp in a separate array? Could we just do these two lines inline instead of in a separate loop?
- temp.push(value);
+ delete this.storageMap[value];
+ this.recentKeys.delete(value);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it modifies the Set and most likely breaks iterator
a6af414
mountiny
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roryabraham all yours
Turned out that during chat switching we have cases when we remove several items at the same time.
In those cases we don't want to recreate iterator.
Details
Related Issues
GH_LINK
Automated Tests
Linked PRs