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-06-06] [$250] [Search v1] Search page scroll is not smooth #41581

Closed
6 tasks
luacmartins opened this issue May 3, 2024 · 50 comments
Closed
6 tasks
Assignees
Labels
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 Reviewing Has a PR in review

Comments

@luacmartins
Copy link
Contributor

luacmartins commented May 3, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number:
Reproducible in staging?:
Reproducible in production?:
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by:
Slack conversation:

Action Performed:

  1. Open the search page, Profile > Troubleshoot > New Search Page
  2. Scroll through the list of results
  3. Notice that the items flicker and on mobile the list jumps around

Expected Result:

Scroll should be smooth

Actual Result:

Scroll is not smooth

Workaround:

Can the user still use Expensify without this being fixed? Have you informed them of the workaround?

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

327270767-f00e25f1-47a9-4095-8871-158eefed349b.mov
327281632-1fa5a858-115a-4e45-948b-c8726e76a67e.mp4

Add any screenshot/video evidence

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01fb9b7cf710602d40
  • Upwork Job ID: 1786403109998579712
  • Last Price Increase: 2024-05-03
  • Automatic offers:
    • eh2077 | Reviewer | 0
    • charles-liang | Contributor | 0
Issue OwnerCurrent Issue Owner: @muttmuure
@luacmartins luacmartins added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels May 3, 2024
@luacmartins luacmartins self-assigned this May 3, 2024
@luacmartins luacmartins added the External Added to denote the issue can be worked on by a contributor label May 3, 2024
Copy link

melvin-bot bot commented May 3, 2024

Triggered auto assignment to @muttmuure (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 changed the title [Search v1] Search page scroll is not smooth [$250] [Search v1] Search page scroll is not smooth May 3, 2024
Copy link

melvin-bot bot commented May 3, 2024

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

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

melvin-bot bot commented May 3, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @eh2077 (External)

Copy link

melvin-bot bot commented May 3, 2024

📣 @nharsh94! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
    Screen Shot 2022-11-16 at 4 42 54 PM
    Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

@eh2077
Copy link
Contributor

eh2077 commented May 4, 2024

@nharsh94 Thanks for your proposal. I'm not following your root cause analysis. Can you elaborate on why the scroll is not smooth?

@eh2077
Copy link
Contributor

eh2077 commented May 6, 2024

@nharsh94 Thanks for the update, but your root cause analysis still seems vague to me.

@eh2077
Copy link
Contributor

eh2077 commented May 6, 2024

Still looking for better proposals

@luacmartins
Copy link
Contributor Author

Still looking for proposals

@charles-liang
Copy link
Contributor

charles-liang commented May 7, 2024

Proposal

Please re-state the problem that we are trying to solve in this issue.

[Search v1] Search page scroll is not smooth #41581

What is the root cause of that problem?

  1. Using Google's performance analysis tools, it was found that the most time-consuming tasks were creating and removing components.
截屏2024-05-07 17 40 33
  1. By removing all elements of the item and replacing them with a single text element, the delay issue was improved.
  2. Adding multiple texts increased the scroll delay issue, but it can basically be determined that it's a problem with rendering child elements.
  3. Analyzed using React Dev Tools, as shown in the figure, the time it takes for the TransactionListItem to render child elements is only half the time of the parent element. It is speculated that the problem lies with the parent element itself.
截屏2024-05-07 15 34 22
  1. All functions returning JSX were removed from TransactionListItem.
  2. Analyzed again using React Dev Tools, the previously observed delay has disappeared.
截屏2024-05-07 17 28 54

Summary:
The root cause is that every time you scroll, it removes the TransactionListItem that leaves the visible area and renders new TransactionListItems. Control by windowSize (Default 5 in BaseSelectionList)(The windowSize default 5 means that, in addition to the visible range in the middle, 2 time of elements of the visible height ((windowsize - 1) / 2) = 2) are kept above and below. When the scrolling speed exceeds the rendering speed, elements are recycled instead of being cached. And updateCellsBatchingPeriod (default 50ms) will render according to your scrolling speed.

Rendering the TransactionListItem is too expensive.
the Reason is:

  1. because each instance of TransactionListItem creates new anonymous functions like DateCell, UserCell, and TotalCell.
  2. the OnSelectRow function passed from Search.

Finally, The render requests are blocked the render queue and event handling.

What changes do you think we should make in order to solve the problem?

  1. Setting windowSize and updateCellsBatchingPeriod to the appropriate value in SelectionList in Search.tsx.

https://github.com/charles-liang/ExpensifyApp/blob/charles/src/components/Search.tsx#L50-L52

  1. Move all similar to xxxx from inside TransactionListItem to above TransactionListItem.
    and applying memo along with keyforlist to decide whether to re-render, avoid re-instantiating these functions.

from

const dateCell = (
<TextWithTooltip
shouldShowTooltip={showTooltip}
text={date}
style={[styles.label, styles.pre, styles.justifyContentCenter, isLargeScreenWidth ? undefined : [styles.textMicro, styles.textSupporting]]}
/>

to
https://github.com/charles-liang/ExpensifyApp/blob/charles/src/components/SelectionList/TransactionListItem.tsx#L71-L81
https://github.com/charles-liang/ExpensifyApp/blob/charles/src/components/SelectionList/TransactionListItem.tsx#L162

  1. wrapped with useCallback to prevent multiple copy OnSelectRow in Search

https://github.com/charles-liang/ExpensifyApp/blob/charles/src/components/Search.tsx#L50-L52

What alternative solutions did you explore? (Optional)

N/A

@eh2077
Copy link
Contributor

eh2077 commented May 7, 2024

@charles-liang Thanks for your proposal. It's good to see you tried to pinpoint the root cause by profiling the page.

  1. By removing all elements of the item and replacing them with a single text element, the delay issue was improved.

Do you mean the TransactionListItem here?

  1. All functions returning JSX were removed from TransactionListItem.
  2. Analyzed again using React Dev Tools, the previously observed delay has disappeared.

Can you elaborate on why those functions cause the delay when scrolling?

@charles-liang
Copy link
Contributor

charles-liang commented May 7, 2024

yes. i mean TransactionListItem.
The RCA is that the cost of re-rendering the item is too high, not due to a specific function. Instead, each TransactionListItem should share a component, rather than each TransactionListItem retuen a new component using function. Therefore, all returned JSX should be moved to the external scope. For specifics, please refer to:

contributingGuides/PERFORMANCE.md

Use PureComponent, React.memo(), and shouldComponentUpdate() to prevent re-rendering expensive components.

@eh2077
Copy link
Contributor

eh2077 commented May 7, 2024

@charles-liang Thanks for the update. Can you detail your improvement plan in the third/solution part of your proposal?

@charles-liang
Copy link
Contributor

charles-liang commented May 7, 2024

Do you mean this:
change react 17 to react 18 using createroot instead of AppRegistry.runApplication in src/setup/platformSetup/index.website.ts to turn on concurrent rendering

Maybe like this.

import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App';
import { AppRegistry } from 'react-native';
import Config from './config';
import { checkForUpdates } from './updateUtils'; 
import { startCurrentDateUpdater } from './DateUtils';

const container = document.getElementById('root');
if (container) {
    const root = createRoot(container);

    AppRegistry.registerComponent(Config.APP_NAME, () => App);
    AppRegistry.runApplication(Config.APP_NAME, {
        initialProps: {},
        rootTag: container,
    });

    if (Config.IS_IN_PRODUCTION) {
        checkForUpdates(webUpdater());
    }

    startCurrentDateUpdater();
}

But I've tested it and the effect is not very obvious.

@eh2077
Copy link
Contributor

eh2077 commented May 7, 2024

@charles-liang I mean the main solution

removed All functions returning JSX from TransactionListItem.

This part can be more detail.

@charles-liang
Copy link
Contributor

For example remove below from TransactionListItem

const dateCell = (
        <TextWithTooltip
            shouldShowTooltip={showTooltip}
            text={date}
            style={[styles.label, styles.pre, styles.justifyContentCenter, isLargeScreenWidth ? undefined : [styles.textMicro, styles.textSupporting]]}
        />
    );

Add this before TransactionListItem
in the same file

const dateCell = (showTooltip, date, styles, isLargeScreenWidth)=>(
        <TextWithTooltip
            shouldShowTooltip={showTooltip}
            text={date}
            style={[styles.label, styles.pre, styles.justifyContentCenter, isLargeScreenWidth ? undefined : [styles.textMicro, styles.textSupporting]]}
        />
    );

@eh2077
Copy link
Contributor

eh2077 commented May 7, 2024

Can you add them to your proposal? Also it'll be very helpful if you can provide a branch to test.

@charles-liang
Copy link
Contributor

ok, I update a proposal after taking a time to make a branch for your test.

@charles-liang
Copy link
Contributor

charles-liang commented May 7, 2024

proposal

updated

@eh2077 i add a new branch with the exmaple code for your test. thanks a lot!

https://github.com/charles-liang/ExpensifyApp/blob/charles/src/components/SelectionList/Search.tsx
https://github.com/charles-liang/ExpensifyApp/blob/charles/src/components/SelectionList/TransactionListItem.tsx

I have decoupled the component from TransactionListItem and memo them. This is just a draft for your test and needs further revisions to comply with the code of conduct.

@melvin-bot melvin-bot bot added Weekly KSv2 and removed Daily KSv2 labels May 14, 2024
@eh2077
Copy link
Contributor

eh2077 commented May 18, 2024

Still working on the PR

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels May 30, 2024
@melvin-bot melvin-bot bot changed the title [$250] [Search v1] Search page scroll is not smooth [HOLD for payment 2024-06-06] [$250] [Search v1] Search page scroll is not smooth May 30, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label May 30, 2024
Copy link

melvin-bot bot commented May 30, 2024

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

Copy link

melvin-bot bot commented May 30, 2024

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

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

Copy link

melvin-bot bot commented May 30, 2024

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:

  • [@eh2077] The PR that introduced the bug has been identified. Link to the PR:
  • [@eh2077] 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:
  • [@eh2077] 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:
  • [@eh2077] Determine if we should create a regression test for this bug.
  • [@eh2077] 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.
  • [@muttmuure] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 Daily KSv2 and removed Weekly KSv2 labels Jun 3, 2024
Copy link

melvin-bot bot commented Jun 13, 2024

@charles-liang, @luacmartins, @muttmuure, @eh2077 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@eh2077
Copy link
Contributor

eh2077 commented Jun 14, 2024

Checklist

  • [@eh2077] The PR that introduced the bug has been identified. Link to the PR: This is a performance issue not a bug, so there isn't a specific PR responsible for this issue
  • [@eh2077] 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
  • [@eh2077] 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: N/A, we already have our best practices documented here React Performance Tips
  • [@eh2077] Determine if we should create a regression test for this bug. No

Copy link

melvin-bot bot commented Jun 17, 2024

@charles-liang, @luacmartins, @muttmuure, @eh2077 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

@luacmartins
Copy link
Contributor Author

Are we just missing payment here?

@eh2077
Copy link
Contributor

eh2077 commented Jun 17, 2024

@luacmartins Yes, that's right. Just asking, is it possible to increase the bounty a little bit as it needed more effort than usual bug fixes. I'm also fine if we just do with the default bounty. Thanks

@luacmartins
Copy link
Contributor Author

Thanks for confirming! I think the $250 bounty is still fair in this case.

@eh2077
Copy link
Contributor

eh2077 commented Jun 18, 2024

No problem! Let's just wait for BZ team to issue the payment.

cc @muttmuure

Copy link

melvin-bot bot commented Jun 19, 2024

@charles-liang, @luacmartins, @muttmuure, @eh2077 Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

@muttmuure
Copy link
Contributor

Looking

@muttmuure
Copy link
Contributor

Paid

@github-project-automation github-project-automation bot moved this from Release 1.5: XeroCon 2024 (June 12th) to Done in [#whatsnext] #wave-collect Jun 20, 2024
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. Daily KSv2 External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review
Projects
No open projects
Archived in project
Development

No branches or pull requests

4 participants