Improve Onyx.merge performance by informing listeners that a key has changed before persisting it in local storage
See original GitHub issueContext https://expensify.slack.com/archives/C01GTK53T8Q/p1618405920178400
Problem
When we set a key in onyx, the time it takes to inform listeners that they key was set is quite long. This is because we are waiting for the value to be saved to AsyncStorage, but there’s really no need for that wait.
Solution
We can inform listeners that the value has changed at the same time we tell AsyncStorage to save it.
Coming from https://github.com/Expensify/react-native-onyx/issues/63 the Onyx merge path is:
Onyx.merge -> get -> set -> AsyncStorage.setItem -> then(() => keyChanged(key, val))
The idea is to trigger keyChanged
at the same time setItem
or set
is called.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
Improvements to `Onyx.get` · Issue #2762 · Expensify/App · GitHub
Improve Onyx.merge performance by informing listeners that a key has changed before persisting it in local storage #2397.
Read more >LocalStorage, sessionStorage - The Modern JavaScript Tutorial
Web storage objects localStorage and sessionStorage allow to save key/value pairs in the browser. What's interesting about them is that the ...
Read more >Where to write to localStorage in a Redux app? - Stack Overflow
I went ahead with something a little bit different: 1. save persisted state outside of redux. 2. load persisted state inside react constructor(or...
Read more >JavaScript LocalStorage: a Complete Guide
The complete guide on LocalStorage, it's API, a code walkthrough, and various trade-offs and limitations compared to other storage options.
Read more >Change Log for Plesk Onyx
The extension can now be installed on Plesk servers running on Red Hat Enterprise Linux 9. Plesk Migrator 2.22.0. 29 August 2022. Website...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
hmmm from those numbers, it does not look like the change is worth it, agree?
Ok so this is just one test I ran but perhaps there are some better ideas…
Test
From completely empty storage measure the time it takes for
Onyx.merge()
to set post downloadedreportActions
data to storage and then update the subscriber of the active report. This does not take into account network request time only the time between when data is returned from thefetch()
and when the component props are updated with this data.The before is with
keyChanged()
called afterset()
resolves and the after is withkeyChanged()
called beforeset()
resolves.Web
Before:
Timing:expensify.cash.fetchActionsAndDataAvailableToOnyx 58
After:
Timing:expensify.cash.fetchActionsAndDataAvailableToOnyx 52
iOS
Before:
Timing:expensify.cash.fetchActionsAndDataAvailableToOnyx 63
After:
Timing:expensify.cash.fetchActionsAndDataAvailableToOnyx 59
Android
Before:
Timing:expensify.cash.fetchActionsAndDataAvailableToOnyx 558
After:
Timing:expensify.cash.fetchActionsAndDataAvailableToOnyx 482
There is some measurable performance impact, but I’d be curious to see a more global test. In general, moving the call to
keyChanged()
beforeset()
improved timing a bit.Note: Android looks much slower compared to others in this test, but we are comparing Apples to Androids and not all hardware emulation is equal.