Skip to content

[Due for payment 2025-07-14] [$250] Improve the subscribeToKey efficiency in Onyx #64774

@mountiny

Description

@mountiny

Coming from this proposal

Problem

Onyx.connect uses subscribeToKey to subscribe to keys, but it performs an O(n) iteration over all Onyx keys - even for exact key matches.
This inefficiency becomes a major bottleneck on screens with many Onyx connections (e.g., screens with lists having per-item subscriptions). When entering expense chat on an account with 40k Onyx keys, it spends 900ms looping through them multiple times.

Solution

Optimize subscribeToKey by distinguishing between:

  • Non-collection keys - use direct lookup instead of iterating through all keys
  • Collection keys - use current iteration logic

Tested on iOS simulator with 40k keys:

  • App launch: isKeyMatch total time dropped from 770ms to 330ms
  • Expense report screen: isKeyMatch dropped from 900ms to 35ms
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021937284236503470296
  • Upwork Job ID: 1937284236503470296
  • Last Price Increase: 2025-06-23
Issue OwnerCurrent Issue Owner: @adelekennedy

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions