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

[HOLD for payment 2024-12-09] [$250] [Performance] BottomTabBar improve state using Initializer function #53162

Closed
gedu opened this issue Nov 26, 2024 · 20 comments
Assignees
Labels
AutoAssignerNewDotQuality Used to assign quality issues to engineers Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@gedu
Copy link
Contributor

gedu commented Nov 26, 2024

Problem

The BottomTabBar component initializes one of its states using the getChatTabBrickRoad function. This function is being called directly within the useState hook, which means it gets executed on every render, even though it only needs to run during the initial state setup.
Current implementation:

const [chatTabBrickRoad, setChatTabBrickRoad] = useState<BrickRoad>(
    getChatTabBrickRoad(activeWorkspaceID, currentReportID, reports, betas, policies, priorityMode, transactionViolations),
);

This approach causes unnecessary re-execution of getChatTabBrickRoad on every render, leading to performance overhead.

Solution

We can pass getChatTabBrickRoad as an initializer function to the useState hook instead. This ensures the function is only executed once during the initial render, improving performance:
Updated implementation:

const [chatTabBrickRoad, setChatTabBrickRoad] = useState<BrickRoad>(() =>
    getChatTabBrickRoad(activeWorkspaceID, currentReportID, reports, betas, policies, priorityMode, transactionViolations),
);

By making this change, the component avoids unnecessary re-execution of getChatTabBrickRoad on every render. This optimization reduces the render time from approximately ±500ms to just 50-100ms, resulting in a more than 5x performance improvement.

Before

bottomTabBar_BEFORE

After

bottomTabBar_AFTER
Issue OwnerCurrent Issue Owner: @
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021862478694382529016
  • Upwork Job ID: 1862478694382529016
  • Last Price Increase: 2024-11-29
Issue OwnerCurrent Issue Owner: @trjExpensify
@mountiny mountiny added Daily KSv2 AutoAssignerNewDotQuality Used to assign quality issues to engineers labels Nov 26, 2024
Copy link

melvin-bot bot commented Nov 26, 2024

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

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Nov 27, 2024
@gedu
Copy link
Contributor Author

gedu commented Nov 27, 2024

@mountiny PR created

@mountiny mountiny added the Bug Something is broken. Auto assigns a BugZero manager. label Nov 29, 2024
@mountiny
Copy link
Contributor

$250 to @eVoloshchak

Copy link

melvin-bot bot commented Nov 29, 2024

Triggered auto assignment to @trjExpensify (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.

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Nov 29, 2024
@trjExpensify trjExpensify added the External Added to denote the issue can be worked on by a contributor label Nov 29, 2024
@melvin-bot melvin-bot bot changed the title [Performance] BottomTabBar improve state using Initializer function [$250] [Performance] BottomTabBar improve state using Initializer function Nov 29, 2024
Copy link

melvin-bot bot commented Nov 29, 2024

Job added to Upwork: https://www.upwork.com/jobs/~021862478694382529016

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 29, 2024
Copy link

melvin-bot bot commented Nov 29, 2024

Current assignee @eVoloshchak is eligible for the External assigner, not assigning anyone new.

@trjExpensify trjExpensify removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 29, 2024
@trjExpensify
Copy link
Contributor

Not sure why an offer wasn't sent to @eVoloshchak there. 🤔

@rezkiy37
Copy link
Contributor

I've created one more issue where I am going to prevent such problems across the entire project - #53322. Also, I am working on a new Eslint rule - Expensify/eslint-config-expensify#138.

cc @gedu @eVoloshchak @mountiny

@mountiny
Copy link
Contributor

Nice thank you!

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Daily KSv2 labels Dec 2, 2024
@melvin-bot melvin-bot bot changed the title [$250] [Performance] BottomTabBar improve state using Initializer function [HOLD for payment 2024-12-09] [$250] [Performance] BottomTabBar improve state using Initializer function Dec 2, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Dec 2, 2024
Copy link

melvin-bot bot commented Dec 2, 2024

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

Copy link

melvin-bot bot commented Dec 2, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.69-4 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 2024-12-09. 🎊

For reference, here are some details about the assignees on this issue:

  • @gedu does not require payment (Contractor)
  • @eVoloshchak requires payment through NewDot Manual Requests

Copy link

melvin-bot bot commented Dec 2, 2024

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

@eVoloshchak
Copy link
Contributor

Not sure why an offer wasn't sent to @eVoloshchak there. 🤔

@trjExpensify, that's because I request payments via NewDot, all good

@trjExpensify
Copy link
Contributor

Ah cool, got it!

@mountiny
Copy link
Contributor

mountiny commented Dec 5, 2024

@eVoloshchak can you please complete the checklist?

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Dec 9, 2024
Copy link

melvin-bot bot commented Dec 9, 2024

Payment Summary

Upwork Job

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

BugZero Checklist (@trjExpensify)

  • I have verified the correct assignees and roles are listed above and updated the neccesary manual offers
  • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/1862478694382529016/hired)
  • I have paid out the Upwork contracts or cancelled the ones that are incorrect
  • I have verified the payment summary above is correct

@trjExpensify
Copy link
Contributor

Can we get the checklist here, please? Thanks!

@eVoloshchak
Copy link
Contributor

  • The PR that introduced the bug has been identified. Link to the PR: technically this was caused by RBR display in LHN, Inbox and Workspace list #46575, since that's the PR that added this particular initializer function. But this is an app-wide issue (that is being tackled in [HOLD for payment 2024-12-17] [HOLD for payment 2024-12-16] [$250] [Performance] Use initializer callbacks for useState #53322), so there is no particular PR at fault
  • The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: N/A
  • A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: This is not a bug, but a performance improvement
  • Determine if we should create a regression test for this bug: same as above, this is not possible to test for QA

@trjExpensify
Copy link
Contributor

Sounds good to me, thanks! Confirming payment summary as follows:

Go ahead and request!

@JmillsExpensify
Copy link

$250 approved for @eVoloshchak

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 Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
Development

No branches or pull requests

6 participants