Repository navigation
Description
Overview
This issue is part of our current effort to audit the performance and scalability of Onyx.
During the Step 1: Objective Analysis we gathered a list of Perceived Problems we have exclusively about Onyx, that is, the problems in Onyx we imagine or have some evidences that that are pain points / performance bottenecks to Onyx, but we need more analysis to confirm if they really are and, if so, how much of a problem they are currently.
The main goal right now is to deep dive into each Perceived Problem, investigate/audit it and come up with findings, which we will use for the next discussions.
Problem
At the moment we use SQLite (react-native-nitro-sqlite) in native platforms and LocalStorage (idb-keyval) in web to store user's data. In both providers, all data is stored in one table as key-value pairs. In the Native provider we use SQL operations to read/write data, but we noticed that they don't seem too much performant. For example, we measured in the past that a simple setItem() operation was taking longer than multiMerge()/mergeItem() even for simple objects, which seem contradictory as we are literally asking DB to fully replace that object and it is somehow slower than doing a merge operation.
Additionally, we don't have means to measure them automatically with unit/Reassure tests, so it's difficult to know if they are working as expected, how they are performing and if these providers need improvements or not.
Action Items
- Audit the two providers and measure how they performing in each one of their operations.
- Research if it's possible to create automated tests for them.
Relevant Links
Step 1 Canvas: https://expensify.slack.com/docs/T02P6RS2ZK7/F09B668M1MG
Slack thread: https://expensify.slack.com/archives/C05LX9D6E07/p1757416490706049
Issue Owner
Current Issue Owner: @mallenexpensifyMetadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fabioh8010 commentedon Sep 29, 2025
Updates:
fabioh8010 commentedon Oct 6, 2025
Updates:
fabioh8010 commentedon Oct 8, 2025
Updates:
fabioh8010 commentedon Oct 13, 2025
DB audit
For this audit I analysed the two providers we have (IDB and SQLite) and performed a series of measurements around the Storage functions we have. For each operation we have a table with the data type used to measure and the execution time of the functions involved from left to right.
IDBKeyValProvider (Web)
setItem (100 executions)
multiSet (1000 records; 100 executions)
mergeItem (100 executions)
multiMerge (1000 records; 100 executions)
getItem (100 executions)
multiGet (1000 records; 100 executions)
SQLiteProvider (Native)
setItem (100 executions)
multiSet (1000 records; 100 executions)
mergeItem (100 executions)
multiMerge (1000 records; 100 executions)
getItem (100 executions)
multiGet (1000 records; 100 executions)
First issues noticed
🐞 IDBKeyValProvider - setItem removes and redundantly sets the value to null
When passing
nulltosetItem, it will remove the item in DB by callingremoveItemand also set the item to null right after it. It's a minor issue because when removing keys we would callremoveItemdirectly, but it's still wrong and it's pretty easy to fix – make a early return after theremoveItemcall. It might be worth to check if we are supposed to have null values being passed to multiMerge too.🐞 IDBKeyValProvider - multiSet calls multiple removeItem's instead of delMany
When calling
multiSetwith some keys that we want to be removed (nullvalue), this logic will call one separateremoveItemfor each key. This could be optimized to get the list of keys that we want to remove and then just calldelManypassing all them, same as we do withsetManyin the line below. This optimization could reduce the execution time formultiSetreported above.🐞 IDBKeyValProvider - multiMerge calls multiple removeItem's instead of using the transaction
When calling
multiMergewith some keys that we want to be removed (nullvalue), this logic will call one separateremoveItemfor each key. This could be optimized to get the list of keys that we want to remove and then callstore.deletefor each one in that transaction, same as we do withstore.putin the line below. It might be worth to check if we are supposed to have null values being passed to multiMerge too.Early conclusions so far
Next steps
Onyx.updateoperations as a single transaction – possibly with a new Storage method dedicated to it. Measure the performance of having this approach.fabioh8010 commentedon Oct 27, 2025
Updates:
@VickyStash is handling this one, some early analysis here.
I started this one.
fabioh8010 commentedon Nov 3, 2025
Updates:
Being mostly addressed here and here.
Went back to this one today, analysing some options and ideas with AI.
For this one, the main challenge was to test the native provider (SQL) in Jest environment, but this might not be impossible anymore with https://www.react-native-harness.dev/ 🎉 It's an experimental library being developed at Callstack but it would provide means for us to execute tests in native environments, making possible test the native providers in Android and iOS.
For web (IDB), I think we can use https://github.com/dumbmatter/fakeIndexedDB to emulate IndexedDB in-memory and perform tests normally with Jest.
fabioh8010 commentedon Nov 14, 2025
SQL Improvements
I experimented some improvements in the SQL queries/provider logic (commit):
multiGetoptimization (chunked / temp-table join): Reduce query parsing and variable binding overhead from very longIN (?, ?, ...)clauses, and improve scalability for large batches.json()wrappers from SQL statements: Eliminate redundantjson()calls around parameters, which parse and re-encode JSON strings inside SQLite.multiGetdifference was insignificant in terms of performance for 1000 records, but we got good results when running operations with 10000 records. We need to double-check and validate the logic if we want to move with this, but I believe it makes sense and we could even remove the small batch part because measurements shown it was already irrelevant for 1000 records.multiMergeandmultiSetin both measurements, due to the removal of the uselessjson(). They are not needed because we already perform JSON parsing/validation when stringifying the JSON.multiGetfor example was making the app crash after some amount of runs.fabioh8010 commentedon Nov 16, 2025
MMKV Storage
getItem,multiGet,setItemandmultiSetwere considerably faster.mergeItemandmultiMergegot significantly worse, probably because I need to get each key from DB, merge the value withfastMergeand then set it again (like we do in IDBKeyValProvider). This summing with the fact we don't have batch operations in MMKV contributed to these results.Conclusions:
fabioh8010 commentedon Nov 16, 2025
OP-SQLite
mergeItem,multiGetwere a bit faster, but insignificantly.Conclusions:
20 remaining items
[-][Onyx Audit] Inefficient DB operations[/-][+][Due for payment 2026-01-21] [Onyx Audit] Inefficient DB operations[/+]melvin-bot commentedon Jan 14, 2026
Reviewinglabel has been removed, please complete the "BugZero Checklist".melvin-bot commentedon Jan 14, 2026
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.1-1 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:
If no regressions arise, payment will be issued on 2026-01-21. 🎊
For reference, here are some details about the assignees on this issue:
[-][Due for payment 2026-01-21] [Onyx Audit] Inefficient DB operations[/-][+][Onyx Audit] Inefficient DB operations[/+]fabioh8010 commentedon Jan 22, 2026
@mountiny @tgolen
Coming from here. Let's close this one:
I will create the two child issues soon.
mallenexpensify commentedon Jun 19, 2026
Payment Summary
Contributor+: @shubham1206agra due $375 via NewDot
JmillsExpensify commentedon Jul 12, 2026
$375 approved for @shubham1206agra