Skip to content

[Due for payment 2025-07-30] [Due for payment 2025-07-22] Improve Onyx.set performance with optional flags for derived values #65715

@TMisiukiewicz

Description

@TMisiukiewicz

Coming from https://expensify.slack.com/archives/C05LX9D6E07/p1751978498770109

Background
Our app uses a derived value system where values are computed from entire collections. Even when the computation itself is fast (often <5ms), we spend significantly more time (hundreds of milliseconds) inside Onyx internals when writing these large derived values to storage.

Problem
Onyx.set isn’t optimized for large objects like derived values. It performs a deep equality check against the cached value and recursively removes nulls, both of which become performance bottlenecks as object size grows.

Solution
Add an options parameter to Onyx.set with two flags:

  • skipCacheCheck: skips the deep equality check
  • skipNullRemoval: skips pruning null values

For derived values, we fully control their lifecycle and recompute them when any dependency changes - so we know the value is new and don’t need a deep comparison. Also, null may be a legitimate result of the computation, so pruning it is unnecessary. Skipping these two checks significantly improves performance when working with large objects.

Comparison made on a derived value we should have merged soon in this PR: #65247
Before: 165ms
After: <5ms

Issue OwnerCurrent Issue Owner: @VictoriaExpensify

Metadata

Metadata

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions