perf: skip per-key clone when Onyx.init() hydrates the cache - #821
Draft
WojtekBoman wants to merge 1 commit into
Draft
perf: skip per-key clone when Onyx.init() hydrates the cache#821WojtekBoman wants to merge 1 commit into
WojtekBoman wants to merge 1 commit into
Conversation
Contributor
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
Onyx.init()loaded the persisted database intoOnyxCachethroughmerge(), which runsfastMerge(existing, value)per key. At init timeexistingis alwaysundefined, sofastMergenever actually merges anything - it just walks and deep-clones every nested object of every row for no reason. On a heavy account this clone-heavy cache-write phase was measured at ~29% of totalOnyx.init()time.Adds
OnyxCache.hydrate(), a bulk-load variant used only byOnyx.init(). Values are stored by reference when safe (utils.needsNormalization()is a read-only, non-allocating check for nested null/undefined and the internalONYX_INTERNALS__REPLACE_OBJECT_MARK). Falls back to the existingfastMergepath in two cases: the key already has a value in cache (a cross-tab sync listener can race ahead of init and write a key beforehydrate()reaches it), or the value itself needs normalizing.OnyxUtils.ts'sinitializeWithDefaultKeyStates()now callscache.hydrate(allDataFromStorage)instead ofcache.merge(allDataFromStorage).Related Issues
GH_LINK
Linked E/App PR
Automated Tests
No automated test added in this diff yet. Needed before merge: an equivalence test asserting
hydrate()produces identical cache state tomerge()on an empty cache, with fixtures for nested nulls, nestedundefined, the replace-object mark, and plain values.Manual Tests
Verify that the app boots normally, the LHN and reports render with the same data as before the change, and no console errors appear.
nullon disk).Verify that the report renders correctly with those fields absent, matching pre-change behavior.
Verify that tab B's cache ends up consistent with tab A's write - i.e. the value isn't clobbered by
hydrate()'s bulk load racing the cross-tab sync listener.Offline tests
Verify that the app boots with the last-persisted cache (same as before this change) and no data is lost or duplicated.
QA Steps
Same as tests.
Author Checklist
### Related Issuessection above### Linked E/App PRsection above, and verified this change against it (E/App CI passed and manual testing completed)TestssectiontoggleReportand 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: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari