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
[Due for payment 2025-07-04] [$250] Improve calculating reports displayed in LHN #64075
Background getOrderedReportIDs is a core function that determines which reports show up in the LHN and in what order. It’s consistently ranked as the most performance-intensive function in the app’s runtime.
Problem getOrderedReportIDs is re-executed on an entire report collection multiple times per user action because its useCallback has several Onyx-driven dependencies.
For example, creating an expense updates transactionViolations, report (twice), and reportActions, all of which are part of the dependency array. Each update causes a full recomputation of LHN visibility and order.
On an Android account with ~7.5k reports, each call takes ~700ms. With 4 updates on Onyx, that’s ~2.8s wasted recalculating the entire list, even though most reports haven’t changed.
Solution
To avoid recalculating the entire report list on every Onyx change:
decouple visibility logic from sorting
use sourceValue to update only the reports that changed based on Onyx updates
This allows to evaluate visibility only for the affected reports, instead of looping through an entire collection. Sorting should remain unchanged.
Tests on Android on an account with 7.5k reports gives the following results:
Create expense: 8.8s → 7.5s
Send message: 2.6s → 2.1s
Tests on iOS indicate dropping the time of LHN reports calculations from 1.1s to 18ms
Please re-state the problem that we are trying to solve in this issue.
The core issue is that the getOrderedReportIDs function is being re-executed multiple times for a large set of reports (up to 7.5k) whenever Onyx updates occur — even if only a few reports are affected. This results in a significant performance hit, especially on mobile devices like Android, leading to degraded user experience in the Left-Hand Navigation (LHN).
What is the root cause of that problem?
The root cause is that getOrderedReportIDs is wrapped in a useCallback hook with multiple Onyx-driven dependencies (reports, reportActions, transactionViolations, etc.). Each update to any of these dependencies triggers a full recomputation over the entire reports collection. However, in most cases, only a small subset of reports has changed, making the recomputation wasteful and unnecessary.
What changes do you think we should make in order to solve the problem?
We propose decoupling the visibility logic from the sorting logic and making the function incremental:
Introduce incremental updates using sourceValue
Leverage sourceValue provided by Onyx to identify which specific reports have changed and only update the visibility status for those reports.
Cache the computed LHN visibility state and only recompute diffs
Maintain a cache of visible reports and update only the affected entries based on Onyx changes. This avoids looping through the entire reports collection.
Leave sorting logic untouched
Once the visible reports are identified (through incremental logic), proceed with the same sorting mechanism, as sorting logic is deterministic and less expensive than full visibility recomputation.
By isolating visibility checks to only impacted reports, we can significantly reduce the time complexity and improve perceived performance.
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
Visibility toggling: Ensure that adding or updating a report with isPinned, hasErrorsOtherThanFailedReceipt, hasValidDraftComment, or requiresAttention properly reflects in the LHN.
Selective re-evaluation: Validate that only affected reports trigger a visibility update, not the entire collection.
Report sorting correctness: Confirm that after visibility filtering, sorting still respects the correct order for each group (pinned, error, draft, non-archived, archived) and by the appropriate criteria (displayName, lastVisibleActionCreated).
Regression tests: Benchmark against large datasets (e.g., 7.5k reports) to ensure performance remains stable or improved across LHN-related user actions like sending messages, creating expenses, and archiving reports.
What alternative solutions did you explore? (Optional)
Memoization with deep equality checks: Explored but rejected due to high overhead of deep comparisons across thousands of reports.
Splitting the hook across multiple useCallbacks: Considered but would add complexity and might not fully solve recomputation due to shared state dependencies.
Throttle/debounce re-computations: Not ideal as it introduces delays and doesn't eliminate unnecessary calculations.
changed the title [-][$250] Improve calculating reports displayed in LHN[/-][+][Due for payment 2025-07-04] [$250] Improve calculating reports displayed in LHN[/+]on Jun 27, 2025
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.71-11 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:
@c3024@jliexpensify@c3024 The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]
Activity
TMisiukiewicz commentedon Jun 12, 2025
@mountiny can I get assigned to this?
[-]Improve calculating reports displayed in LHN[/-][+][$250] Improve calculating reports displayed in LHN[/+]nabi-ebrahimi commentedon Jun 12, 2025
Proposal
Please re-state the problem that we are trying to solve in this issue.
The core issue is that the
getOrderedReportIDsfunction is being re-executed multiple times for a large set of reports (up to 7.5k) whenever Onyx updates occur — even if only a few reports are affected. This results in a significant performance hit, especially on mobile devices like Android, leading to degraded user experience in the Left-Hand Navigation (LHN).What is the root cause of that problem?
The root cause is that
getOrderedReportIDsis wrapped in auseCallbackhook with multiple Onyx-driven dependencies (reports,reportActions,transactionViolations, etc.). Each update to any of these dependencies triggers a full recomputation over the entire reports collection. However, in most cases, only a small subset of reports has changed, making the recomputation wasteful and unnecessary.What changes do you think we should make in order to solve the problem?
We propose decoupling the visibility logic from the sorting logic and making the function incremental:
Introduce incremental updates using
sourceValueLeverage
sourceValueprovided by Onyx to identify which specific reports have changed and only update the visibility status for those reports.Cache the computed LHN visibility state and only recompute diffs
Maintain a cache of visible reports and update only the affected entries based on Onyx changes. This avoids looping through the entire reports collection.
Leave sorting logic untouched
Once the visible reports are identified (through incremental logic), proceed with the same sorting mechanism, as sorting logic is deterministic and less expensive than full visibility recomputation.
By isolating visibility checks to only impacted reports, we can significantly reduce the time complexity and improve perceived performance.
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
isPinned,hasErrorsOtherThanFailedReceipt,hasValidDraftComment, orrequiresAttentionproperly reflects in the LHN.displayName,lastVisibleActionCreated).What alternative solutions did you explore? (Optional)
jliexpensify commentedon Jun 12, 2025
@mountiny just checking - should this be external, or are people already assigned to work on it?
mountiny commentedon Jun 12, 2025
@TMisiukiewicz Is working on this
melvin-bot commentedon Jun 16, 2025
@TMisiukiewicz Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
10 remaining items
[-][$250] Improve calculating reports displayed in LHN[/-][+][Due for payment 2025-07-04] [$250] Improve calculating reports displayed in LHN[/+]melvin-bot commentedon Jun 27, 2025
Reviewinglabel has been removed, please complete the "BugZero Checklist".melvin-bot commentedon Jun 27, 2025
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.71-11 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:
If no regressions arise, payment will be issued on 2025-07-04. 🎊
For reference, here are some details about the assignees on this issue:
melvin-bot commentedon Jun 27, 2025
@c3024 @jliexpensify @c3024 The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]
jliexpensify commentedon Jul 4, 2025
Payment Summary
Bump @c3024 for checklist!
melvin-bot commentedon Jul 4, 2025
Payment Summary
Upwork Job
BugZero Checklist (@jliexpensify)
c3024 commentedon Jul 4, 2025
This is a performance improvement. No checklist nor regression test is required.
jliexpensify commentedon Jul 6, 2025
Great, thanks! Payment summary here.
twisterdotcom commentedon Jul 28, 2025
@c3024 has submitted payment for this report on ND here.
SO: https://stackoverflowteams.com/c/expensify/questions/7582
Zapier Logs
Run ID: 00040eee-6d07-a246-927c-8ec40d8b5881