[No QA] perf: replace reduce with for-of in reportsByPolicyID to reduce GC pressure#94980
Conversation
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
Reviewer Checklist
Screenshots/VideosAndroid: HybridApp2026-06-30.17.10.08.movAndroid: mWeb Chrome2026-06-30.17.10.08.moviOS: HybridApp2026-06-30.17.18.31.moviOS: mWeb Safari2026-06-30.17.10.08.movMacOS: Chrome / Safari2026-06-30.17.08.19.mov |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.26-0 🚀
|
|
🤖 Help site review — no changes required I reviewed the changes in this PR against the help site articles under This is a pure internal performance refactor: it replaces The change is semantically identical to the previous code — no user-facing behavior, feature, UI label, tab name, setting, or copy is added or altered. Help site articles document product behavior for end users, and nothing documented there is affected by this optimization. Conclusion: No help site changes are required, so no draft docs PR was created. |
|
🚀 Deployed to production by https://github.com/grgia in version: 9.4.27-2 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Both
ReportUtils.ts(the deprecated Onyxconnectcallback) andoutstandingReportsByPolicyID.ts(the OnyxDerived config) built a policy→reports map usingObject.entries(...).reduce(...). Each iteration spread the accumulator object ({ ...acc[policyID], [reportID]: report }), creating a new intermediate object per report. On accounts with many reports this produces heavy short-lived allocation, increasing GC pressure.The change replaces both
reducecalls with a plainfor...ofloop that mutates a local object in place. The result is semantically identical but eliminates the per-iteration spread allocation entirely.Performance improvement
On Android production build, the total time of both report-grouping loops dropped from ~200ms to ~90ms. The old code rebuilt each policy's bucket with a spread copy on every insert
({...acc[policyID], ...}), generating O(K²) short-lived objects per policy; the new in-place version allocates each bucket once. That churn was also causing GC-pressure spikes up to ~400ms — those are now entirely gone.Fixed Issues
$ #94985
Tests
No tests needed, pure refactor
Offline tests
N/A
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)Avatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari