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-01-03] [HOLD for payment 2023-12-28] [Performance] Search input performance optimization #32806

Closed
mountiny opened this issue Dec 11, 2023 · 13 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Weekly KSv2

Comments

@mountiny
Copy link
Contributor

Coming from this performance proposal:

Problem:

Currently, when users type in the search input in Money Request Participant List search, each keystroke triggers re-rendering of Option List, which is preceded by heavy calculations in the getOptions function, leading to significant performance overhead. Comparing the execution time of this function on Web:

  • Account with 66 reports and 4200 personal details → 45ms
  • Account with 15330 reports and 12 personal details → 650ms

With keystrokes calling such expensive function, this results in a laggy user experience, as the app processes each input individually without any delay or optimization. The continuous processing of these inputs strains the app’s resources, causing slowdowns and delays in displaying search results.

Additionally, each keystroke is causing unnecessary re-renders in the list items that could be avoided to reduce the consumption of the CPU.

### Solution:
To address this problem, we could do a few steps that should positively impact the usage of search:

  1. Debouncing the search value update - this will allow to call expensive calculations only after the user stopped typing for a specified duration (e.g. 200 ms). So, when typing “Andrew”, the getOptions would run only once instead of 6 times (unless there will be a pause while typing)
  2. Memoizing components to avoid unnecessary re-renders - currently, when typing in the input, a lot of components are getting unnecessarily re-rendered - e.g. each list item and BaseOptionSelector. Memoizing BaseOptionsSelector and fixing wrong memo condition !_.isEqual(prevProps.option.icons, nextProps.option.icons) causing re-renders on each keystroke.
  3. We could stop using debounce on search in server, since with a debounced search value update it won’t be necessary anymore.

Comparing the results on the account with 15330 reports on Web:
Action: write adg in the search
Metric: getOptions call count Before: 4 After: 1
Metric: max JS heap Before: 595mb After: 306mb
Metric: MoneyRequestParticipantSelector max render time Before: ~110ms After: ~75ms
Metric: Single list item render count Before: 4 After: 1

Comparing account with 4200 personal details on Android - you can see attached screenshot of CPU usage from Flashlight. The blue line indicates the CPU usage while writing my email address “tomasz.misiukiewicz@callstack.com” and having getOptions method called on each keystroke. CPU usage for JS thread is around 100% all the time. The yellow line indicates CPU usage when calling getOptions function is debounced - the usage jumps only when there was a pause in typing longer than the debounce time.

This changes will also benefit other lists using OptionsSelector component:

  • CategoryPicker
  • TagPicker
  • NewChatPage
  • SearchPage
  • TaskAssigneeSelectorModal
  • TaskShareDestinationSelectorModal

Few of them already have debouncing implemented, but they have different amount of milliseconds set, so we can unify them. Additionally each one of them will benefit from reduced amount of re-renders of list items.

@mountiny mountiny added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Dec 11, 2023
@mountiny mountiny self-assigned this Dec 11, 2023
Copy link

melvin-bot bot commented Dec 11, 2023

Triggered auto assignment to @kadiealexander (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

Copy link

melvin-bot bot commented Dec 11, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@TMisiukiewicz
Copy link
Contributor

Hi, I'm Tomasz from Callstack and I'd like to work on that issue

@kadiealexander
Copy link
Contributor

Not overdue!

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Overdue Daily KSv2 labels Dec 14, 2023
Copy link

melvin-bot bot commented Dec 19, 2023

⚠️ Looks like this issue was linked to a Deploy Blocker here

If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

If a regression has occurred and you are the assigned CM follow the instructions here.

If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

Copy link

melvin-bot bot commented Dec 19, 2023

⚠️ Looks like this issue was linked to a Deploy Blocker here

If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

If a regression has occurred and you are the assigned CM follow the instructions here.

If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Dec 20, 2023
@melvin-bot melvin-bot bot changed the title [Performance] Search input performance optimization [HOLD for payment 2023-12-28] [Performance] Search input performance optimization Dec 21, 2023
Copy link

melvin-bot bot commented Dec 21, 2023

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

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Dec 21, 2023
Copy link

melvin-bot bot commented Dec 21, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.14-6 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 2023-12-28. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

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

Copy link

melvin-bot bot commented Dec 21, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@mountiny] The PR that introduced the bug has been identified. Link to the PR:
  • [@mountiny] 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:
  • [@mountiny] 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:
  • [@TMisiukiewicz] Determine if we should create a regression test for this bug.
  • [@TMisiukiewicz] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@kadiealexander] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

Copy link

melvin-bot bot commented Dec 26, 2023

⚠️ Looks like this issue was linked to a Deploy Blocker here

If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

If a regression has occurred and you are the assigned CM follow the instructions here.

If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

@melvin-bot melvin-bot bot added Daily KSv2 Weekly KSv2 and removed Weekly KSv2 Daily KSv2 labels Dec 27, 2023
@melvin-bot melvin-bot bot changed the title [HOLD for payment 2023-12-28] [Performance] Search input performance optimization [HOLD for payment 2024-01-03] [HOLD for payment 2023-12-28] [Performance] Search input performance optimization Dec 27, 2023
Copy link

melvin-bot bot commented Dec 27, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.17-8 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-01-03. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

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

Copy link

melvin-bot bot commented Dec 27, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@mountiny] The PR that introduced the bug has been identified. Link to the PR:
  • [@mountiny] 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:
  • [@mountiny] 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:
  • [@TMisiukiewicz] Determine if we should create a regression test for this bug.
  • [@TMisiukiewicz] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@kadiealexander] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@mountiny
Copy link
Contributor Author

This is new feature and performance related I think no regression tests are needed we are working on new automated perf tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Weekly KSv2
Projects
Development

No branches or pull requests

3 participants