Skip to content

[Tracking] Implement JSON_PATCH() in Onyx.merge() in react-native-onyx(native) #13972

Description

@tgolen

Design Doc: https://docs.google.com/document/d/1Aw3gB8ksT5b1xGBtoAKSPR5pcBXHh9yjmRWv8GGdbXM/edit

Proposal:

Move manual merging to LocalForage, since in SQLiteStorage this is already done with JSON_PATCH

Problem:

Onyx is our low level state management layer. We need this layer to be as fast as possible on native devices as everything the user sees and does is driven by this layer. At the moment when data is merged into Onyx we perform a series of inefficient steps:

  • In the past we had to solve a race condition related to our asynchronous storage providers (AsyncStorage and LocalForage) when making updates in a single tick of the event loop. To solve this, we had to queue partial updates into a batch, get the most up to date data from storage, and then merge the queue into the existing data and replace the entire key.
  • On native, this requires that we potentially pull large objects out of device storage and send them across React Native bridge.
  • We must also serialize and deserialize this data which can be an expensive task to perform especially on native.

Solution:

To properly separate logic for native vs. web, we should have different merge logic for each data provider. My solution would be to move the manual merge to LocalForage.js’s merge function and keep JSON_PATCH in case of conflicts in SQLiteStorage.js


Tasks:

  • Post Proposal (Problem/Solution) in #expensify-open-source
  • Link to P/S: https://expensify.slack.com/archives/C01GTK53T8Q/p1672862201064419
  • Post P/S in this issue description
  • Email strategy@expensify.com with Proposal
  • Fill out High-level overview of the problem, Timeline, and Terminology section
  • Email strategy@expensify.com (same email chain as before) with link to Design Doc
  • Host a pre-design meeting in #expensify-open-source to discuss any necessary details in public before filling out the High-level of proposed solution section
  • Fill out the High-level of proposed solution section
  • Email stategy@expensify.com again with links to the doc and pre-design conversation in Slack
  • Add DesignDocReview label to get the High-level of proposed solution section reviewed
  • Respond to any questions or concerns and bring up blockers in Slack to get consensus if necessary
  • Confirm that the doc has the minimum necessary number of reviews before proceeding
  • Host another pre-design meeting in #expensify-open-source to ask for engineering feedback on the technical solution.
  • Fill out the Detailed implementation of the solution and related sections.
  • Re-add the DesignDocReview
  • Respond to any questions or concerns and bring up blockers in Slack to get consensus if necessary
  • Confirm that the doc has the minimum necessary number of reviews before proceeding
  • Email strategy@expensify.com one last time to let them know the Design Doc is moving into the implementation phase
  • Implement the changes

Metadata

Metadata

Labels

MonthlyKSv2NewFeatureSomething to build that is a new item.ReviewingHas a PR in review

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions