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 report ordering in the LHN #10784

Merged
merged 50 commits into from
Sep 13, 2022
Merged

Conversation

tgolen
Copy link
Contributor

@tgolen tgolen commented Sep 2, 2022

This is the first step in optimizing the ordering logic of the sidebar. It does these things:

  1. Removes all state data from the SidebarLinks component, which removes the need for setDerivedStateFromProps and any other static methods
  2. It makes the rendering so efficient that it doesn't really matter how many times it's re-renderes or how many items it has
  3. It optimizes all the stuff happening in OptionsListUtils so that it's very efficient and only doing the minimum amount of logic in the fastest way

Fixed Issues

Part of #7948

Tests

Everything is covered by unit tests, but in general you need to test:

  1. Chats in the LHN show as draft, pinned, unread, and have outstanding IOUs and that changes those states updates the LHN appropriately
  2. Switching view mode changes the views as expected

Screenshots

Web

Mobile Web

Desktop

iOS

Android

Copy link
Contributor Author

@tgolen tgolen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated and ready for another review!

focusedIndex={_.findIndex(this.state.orderedReports, (
option => option.reportID === activeReportID
focusedIndex={_.findIndex(this.orderedReports, (
option => option.reportID.toString() === this.props.currentlyViewedReportID.toString()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

option.reportID comes from Onyx, where it's stored as a number, because PHP is sending it as a number. The second one is already a string, so I've removed the unnecessary .toString() from it.

This will ultimately be cleaned up in https://github.com/Expensify/Expensify/issues/227425

@@ -158,18 +158,37 @@ Onyx.init({
});

function getDefaultRenderedSidebarLinks() {
class ErrorBoundary extends React.Component {
// Error boundaries have to implement this method. It's for providing a fallback UI, but
// we don't need that for unit testing, so this is basically a no-op.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a big code comment to explain the why behind why this is necessary.

@tgolen
Copy link
Contributor Author

tgolen commented Sep 8, 2022

I haven't had the time to test this on all platforms, but I would like to do that before this is merged. Maybe I'll have the time to do this tomorrow.

@marcaaron
Copy link
Contributor

Tested on iOS and Desktop. Seems to be working very well.

Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are looking good to me. I'd be curious to see some before and after snapshots to get a better idea of which changes impacted performance the most, but that is NAB.

I also think it would be good to distill any of the things we learned here and add them to the PERFORMANCE.md doc with some tips on when some of the strategies used in this PR would be appropriate to use.

@tgolen
Copy link
Contributor Author

tgolen commented Sep 9, 2022

Thanks, Marc! I'm trying to test on Android... and it's, totally unusable. I get the feeling though that it's not related to my branch and only related to the sheer number of reports. For example, I'm seeing errors like this:

image

@tgolen
Copy link
Contributor Author

tgolen commented Sep 9, 2022

I also see these logs, which indicate that while it takes ~220ms on web to sort and filter the reports, it's taking almost 30 seconds on android.

Timing:expensify.cash.sidebar_links_filter_reports 31150

@tgolen
Copy link
Contributor Author

tgolen commented Sep 9, 2022

Hm, OK. Same thing is happening on main, so I don't think this branch is causing it (or fixing it unfortunately). I think maybe when I get the second PR done, that's when it might start working 🤞

@tgolen
Copy link
Contributor Author

tgolen commented Sep 9, 2022

As I was doing some performance testing this morning, to get you snapshots of main vs. this branch, it's pretty interesting.

This branch actually doesn't change much the rendering time of the LHN. BUT it achieves the same performance as main without having all of the memoized methods and the serDerivedStateFromProps().

Where we're really going to see the performance gains is in #10800

@tgolen
Copy link
Contributor Author

tgolen commented Sep 13, 2022

I'm going to self merge since it's got a couple of reviews. This will let me move onto my next step of optimizing. The two failing tests are OK because there are no contributors involved with this one.

@tgolen tgolen merged commit 23f4fc8 into main Sep 13, 2022
@tgolen tgolen deleted the tgolen-optimize-sidebarordering branch September 13, 2022 15:36
@melvin-bot melvin-bot bot added the Emergency label Sep 13, 2022
@melvin-bot
Copy link

melvin-bot bot commented Sep 13, 2022

@tgolen looks like this was merged without passing tests. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@francoisl
Copy link
Contributor

🚀 Cherry-picked to staging by @francoisl in version: 1.2.0-3 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes.


Note: we had a conflict on the staging branch which ended up needing to be manually fixed, so this PR doesn't automatically appear in the diff between production and staging - so I'm manually adding the note that it was CPed to staging here.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @tgolen in version: 1.2.1-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants