You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[$175] perf: Share policy collection scans between subscribers #108486
BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in reviewWeeklyKSv2
On accounts with thousands of workspaces, every write to one workspace made about 30 subscribers each scan the whole policy collection with the same few checks. On an account with about 6000 workspaces, one unrelated policy write cost about 290 to 370 ms of JavaScript on Home.
Solution
The shared policy helpers now cache their result per frozen Onyx collection snapshot, keyed by the login, account ID, or offline state each answer depends on. The first subscriber does the scan and the rest reuse it. The Workspaces tab red dot also remembers each policy's check results, so a write only re-checks the policy that changed. JavaScript work on Home dropped from 286 to 373 ms down to 183 to 222 ms.
changed the title [-]perf: Share policy collection scans between subscribers[/-][+][$175] perf: Share policy collection scans between subscribers[/+]on Dec 1, 2026
Multiple subscribers independently filter the same workspace collection after every policy update. Even when a selector returns an unchanged boolean and prevents a re-render, its collection scan still runs. With thousands of workspaces, those repeated scans accumulate substantial JavaScript work.
Confidence: Medium. The code supports this mechanism; the issue’s subscriber counts and performance measurements were not independently reproduced.
What changes do you think we should make in order to solve the problem?
WalletPage:130–136 uses copy-before-sort rather than mutating a shared result.
Challenges and limitations
This reduces duplicate computation; it does not eliminate collection traversal on each changed snapshot.
Two helpers still perform Object.keys-based emptiness checks before reaching their memo lookup: policy.ts:297–335. Moving those checks inside the cached computation would avoid that remaining repeated enumeration.
In-place mutation could stale cached answers. No concrete regression was found in the intended immutable Onyx update flow.
Before merge, add coverage for account/login/offline transitions, sync-progress-only changes, unchanged-policy predicate reuse across subscribers, and shared-array sorting.
No runtime tests or profiling were performed during this analysis. Controlled before/after profiling remains necessary to substantiate the reported timings; production logs are not needed to establish this client-side computation mechanism.
What alternative solutions did you explore? (Optional)
Narrower selectors reduce re-renders but do not share their computation across subscribers. A fully incremental policy index could avoid more scanning, but requires substantially more invalidation logic.
Next Steps for Contributor+ team: To accept:@MelvinBot implement [this](https://github.com/Expensify/App/issues/108486) to create a draft PR. An implementation PR already exists, so review that first. To refine:@MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.
BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in reviewWeeklyKSv2
Activity
expensify-chore-bot commentedon Dec 1, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @Pujan92 (
External)[-]perf: Share policy collection scans between subscribers[/-][+][$175] perf: Share policy collection scans between subscribers[/+]expensify-chore-bot commentedon Dec 1, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022127793838402679060
MelvinBot commentedon Dec 1, 2026
Proposal
What is the root cause of that problem?
Multiple subscribers independently filter the same workspace collection after every policy update. Even when a selector returns an unchanged boolean and prevents a re-render, its collection scan still runs. With thousands of workspaces, those repeated scans accumulate substantial JavaScript work.
Confidence: Medium. The code supports this mechanism; the issue’s subscriber counts and performance measurements were not independently reproduced.
What changes do you think we should make in order to solve the problem?
Continue with the existing Share policy collection scans between subscribers PR rather than creating another implementation:
Code evidence and remaining validation
Evidence chain
Challenges and limitations
Object.keys-based emptiness checks before reaching their memo lookup: policy.ts:297–335. Moving those checks inside the cached computation would avoid that remaining repeated enumeration.What alternative solutions did you explore? (Optional)
Narrower selectors reduce re-renders but do not share their computation across subscribers. A fully incremental policy index could avoid more scanning, but requires substantially more invalidation logic.
Related issue: Avoid unnecessary Home, Settings and tab bar renders on workspace updates addresses complementary rendering work, rather than duplicate helper computation.
Next Steps for Contributor+ team:
To accept:
@MelvinBot implement [this](https://github.com/Expensify/App/issues/108486)to create a draft PR. An implementation PR already exists, so review that first.To refine:
@MelvinBot <your feedback>To reject: Explain why you are rejecting Melvin's proposal.
view run