Skip to content

[Due for payment 2025-07-04] [$250] Improve calculating reports displayed in LHN #64075

Closed

Description

@TMisiukiewicz

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

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021933164171455873876
  • Upwork Job ID: 1933164171455873876
  • Last Price Increase: 2025-06-12
Issue OwnerCurrent Issue Owner: @jliexpensify

Activity

  1. TMisiukiewicz commented on Jun 12, 2025

    @TMisiukiewicz
    ContributorAuthor

    @mountiny can I get assigned to this?

  2. added
    External
    Daily
    Bug
    on Jun 12, 2025
  3. changed the title [-]Improve calculating reports displayed in LHN[/-] [+][$250] Improve calculating reports displayed in LHN[/+] on Jun 12, 2025
  4. nabi-ebrahimi commented on Jun 12, 2025

    @nabi-ebrahimi
    Contributor

    Proposal

    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:

    1. 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.

    2. 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.

    3. 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.
  5. jliexpensify commented on Jun 12, 2025

    @jliexpensify
    Contributor

    @mountiny just checking - should this be external, or are people already assigned to work on it?

  6. mountiny commented on Jun 12, 2025

    @mountiny
    Contributor

    @TMisiukiewicz Is working on this

  7. removed
    External
    on Jun 12, 2025
  8. melvin-bot commented on Jun 16, 2025

    @melvin-bot

    @TMisiukiewicz Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  9. 10 remaining items

  10. added
    Weekly
    Awaiting Payment
    on Jun 27, 2025
  11. 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
  12. removed
    Reviewing
    on Jun 27, 2025
  13. melvin-bot commented on Jun 27, 2025

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  14. melvin-bot commented on Jun 27, 2025

    @melvin-bot

    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:

    • @TMisiukiewicz does not require payment (Contractor)
    • @c3024 requires payment through NewDot Manual Requests
  15. melvin-bot commented on Jun 27, 2025

    @melvin-bot

    @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]

  16. jliexpensify commented on Jul 4, 2025

    @jliexpensify
    Contributor

    Payment Summary

    • C+: @c3024 $250 (to be paid via New Expensify requests)

    Bump @c3024 for checklist!

  17. added
    Daily
    and removed
    Weekly
    on Jul 4, 2025
  18. melvin-bot commented on Jul 4, 2025

    @melvin-bot

    Payment Summary

    Upwork Job

    • Contributor: @TMisiukiewicz is from an agency-contributor and not due payment
    • Reviewer: @c3024 owed $250 via NewDot

    BugZero Checklist (@jliexpensify)

    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/1933164171455873876/hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  19. c3024 commented on Jul 4, 2025

    @c3024
    Contributor

    This is a performance improvement. No checklist nor regression test is required.

  20. jliexpensify commented on Jul 6, 2025

    @jliexpensify
    Contributor

    Great, thanks! Payment summary here.

  21. twisterdotcom commented on Jul 28, 2025

    @twisterdotcom
    Contributor

    @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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugDaily

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions