Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize drafts reports in useReportIDs to Reduce Renders #54094

Open
gedu opened this issue Dec 13, 2024 · 3 comments
Open

Optimize drafts reports in useReportIDs to Reduce Renders #54094

gedu opened this issue Dec 13, 2024 · 3 comments
Assignees
Labels
AutoAssignerNewDotQuality Used to assign quality issues to engineers Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2

Comments

@gedu
Copy link
Contributor

gedu commented Dec 13, 2024

Background

The useReportIDs hook is responsible for managing the list of report IDs displayed in the sidebar. It uses a combination of useCallback and useMemo to optimize the generation of the ordered report IDs and the context value. However, the current implementation includes reportsDrafts as a dependency in the getOrderedReportIDs callback.
When a draft is updated (e.g., a user types or edits a message), the reportsDrafts changes, causing the getOrderedReportIDs callback to update. This triggers the re-execution of other hooks, including the expensive SidebarUtils.getOrderedReportIDs function, which recalculates the ordered report IDs. This recalculation happens even when the draft content changes but the number of drafts (reportsDrafts) remains the same.

Problem

The useReportIDs hook currently updates the draft state every time content of the draft message is being changed.

Solution

It is super important optimize the useReportIDs hook by changing the dependency on the getOrderedReportIDs callback - from the draft content itself to the number of active drafts. This ensures that renders are only triggered when the draft count changes, not when the content of the draft is updated.

  1. Update the Hook:
    ○ Replace the reportsDrafts with draftAmount as a dependency to the useCallback function in the useReportIDs hook.

Comparison

● Current Implementation: ±11,455.4 ms: Total time spent rendering ReportIDsContextProvider due to frequent updates triggered by draft changes, causing unnecessary recalculations.
● Updated Total: ±4,410.8 ms: Total time after optimizing useReportIDs to update only when the draft count changes, reducing unnecessary renders.
● 7,044.6 ms saved: Significant reduction in render time by avoiding redundant recalculations.

  • Current
useReportIDs_current
  • Updated
useReportIDs_length

Slack: https://expensify.slack.com/archives/C05LX9D6E07/p1733994811786719

Issue OwnerCurrent Issue Owner: @gedu
@gedu
Copy link
Contributor Author

gedu commented Dec 13, 2024

@mountiny I want to work on this issue

@mountiny mountiny added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. AutoAssignerNewDotQuality Used to assign quality issues to engineers labels Dec 13, 2024
Copy link

melvin-bot bot commented Dec 13, 2024

Current assignee @mountiny is eligible for the AutoAssignerNewDotQuality assigner, not assigning anyone new.

Copy link

melvin-bot bot commented Dec 13, 2024

Triggered auto assignment to @sonialiap (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoAssignerNewDotQuality Used to assign quality issues to engineers Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2
Projects
Development

No branches or pull requests

3 participants