-
Notifications
You must be signed in to change notification settings - Fork 87
perf: speed up cache read in useOnyx #647
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
perf: speed up cache read in useOnyx #647
Conversation
|
@TMisiukiewicz how will we ensure the old cache is not used once the app loads with this new structure? |
|
@TMisiukiewicz can you please take the PR out of draft |
|
@allgandalf I'll get back to this on Monday - I want to verify the approach where keys are not duplicated across two objects in memory |
|
@TMisiukiewicz lets keep this one at the top of your list except deploy blockers please, thanks |
|
@mountiny yup I'm on it today |
|
Ok I feel we can proceed with this PR with the current approach. With keeping the indexed collection items as a separate map we can provide a backward compatible solution and avoid building additional complexity around cache eviction. Let me do some more tests before I open PR for a review |
|
Opened PR for a review. Seems like perf tests are failing due to its flakiness |
arosiclair
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.
Changes LGTM
|
Please fix reassure test |
|
@allgandalf The reassure tests are flaky, please proceed with testing with priority and test these changes withing app please. If you are not available for this one, we can re-assign. Thank you |
lib/OnyxCache.ts
Outdated
| * Get all data for a collection key | ||
| */ | ||
| getCollectionData(collectionKey: OnyxKey): Record<OnyxKey, OnyxValue<OnyxKey>> | undefined { | ||
| const memberKeys = this.collectionIndex[collectionKey]; |
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.
Should you use the getCollectionMemberKeys you created?
lib/OnyxCache.ts
Outdated
| this.collectionKeys = collectionKeys; | ||
| // Initialize collection indexes for existing collection keys | ||
| collectionKeys.forEach((collectionKey) => { | ||
| if (this.collectionIndex[collectionKey]) { |
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.
Should you use getCollectionMemberKeys?
lib/OnyxCache.ts
Outdated
| if (value === null || value === undefined) { | ||
| this.addNullishStorageKey(key); | ||
| // Remove from collection index if it's a collection member | ||
| if (collectionKey && this.collectionIndex[collectionKey]) { |
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.
getCollectionMemberKeys
lib/OnyxCache.ts
Outdated
|
|
||
| // Update collection index if this is a collection member | ||
| const collectionKey = this.getCollectionKey(key); | ||
| if (collectionKey && this.collectionIndex[collectionKey]) { |
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.
getCollectionMemberKeys
lib/OnyxCache.ts
Outdated
|
|
||
| // Update collection index if this is a collection member | ||
| if (collectionKey) { | ||
| if (!this.collectionIndex[collectionKey]) { |
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.
getCollectionMemberKeys
lib/OnyxCache.ts
Outdated
| if (value === null || value === undefined) { | ||
| delete this.storageMap[key]; | ||
| // Remove from collection index if it's a collection member | ||
| if (collectionKey && this.collectionIndex[collectionKey]) { |
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.
getCollectionMemberKeys
|
@TMisiukiewicz Can you please merge main to check if the tests are now not flaky anymore cc @fabioh8010 |
|
thank you @mountiny, comments addressed. Updated the branch with main, let's see if Reassure job is green now |
|
Reassure is still failing, I think it is still due to flakiness because it does not seem to be related to my changes 😞 |
|
@TMisiukiewicz yeah I think the same, let me test this PR locally a couple of times. |
|
@TMisiukiewicz @mountiny I ran Reassure on this PR locally a couple of times and we don't have regressions from it |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / SafariScreen.Recording.2025-07-02.at.9.42.11.AM.movMacOS: Desktop |
Details
Performance improvements related to accessing data from cache. Instead of looping on all keys when connecting to entire collection, hold an indexed map for quick access to all collection items.
Related Issues
$ Expensify/App#64950
Automated Tests
Manual Tests
Author Checklist
### Related Issuessection aboveTestssectiontoggleReportand notonIconClick)myBool && <MyComponent />.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)Avataris modified, I verified thatAvataris working as expected in all cases)mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
android.mov
Android: mWeb Chrome
android-web.mov
iOS: Native
ios.mp4
iOS: mWeb Safari
ios.web.mp4
MacOS: Chrome / Safari
web.mov
MacOS: Desktop
desktop.mov