-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Opening a transaction thread can be slow to load sometimes #43384
Opening a transaction thread can be slow to load sometimes #43384
Conversation
🧪🧪 Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing! 🧪🧪
|
Reviewer Checklist
Screenshots/VideosAndroid: NativeAndroid: mWeb ChromeiOS: Nativeios.moviOS: mWeb SafariMacOS: Chrome / Safariweb.movMacOS: Desktop |
@aimane-chnaif what is your ETA for the testing? thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe my account is not heavy enough but transaction detail page loads no more than 1s after api response.
Code looks good and tests well anyway. I am wondering if we should memoize all ReportUtils.getTransactionDetails usages. i.e. DistanceEReceipt, EReceipt
I also considered it, but since it isn't triggered very often and doesn't cause any performance issues (at least from my perspective), I think it's better not to memoize it. |
Does this happen only on the branch with the PR? I couldn't reproduce it neither on current branch nor on main 🤔 |
NVM. This also happens on main but not constantly reproducible. Maybe related to timezone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for testing quick @aimane-chnaif
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/mountiny in version: 1.4.84-0 🚀
|
🚀 Deployed to production by https://github.com/AndrewGable in version: 1.4.84-3 🚀
|
Details
Problem
Opening transaction threads seems to be much slower than opening a chat or an expense report.
Analysis
After investigating, we noticed that in the transaction opening flow, the formatWithUTCTimeZone function was called multiple times (around 2700 times according to the attached trace). On my smaller testing account, it was called approximately 70 times. The main culprit was the getTransactionDetails function, which was called the same number of times, mostly with the same data.
The most impacted components were MoneyRequestPreviewContent.tsx and MoneyRequestView.tsx.
Solution
By adding memoization, we reduced the rendering amount from around 70 to 26! Additionally, we removed the re-rendering that occurred every time a user hovers over the transaction, providing further benefits. This reduced the call counts by more than 250%.
Testing and Results
I tested this on a smaller account, but the percentage gain on larger accounts should be even more substantial!
Future Optimization Considerations
I considered further optimization by memoizing the getTransactionReportName function, which is also called multiple times. However, since it's not a component, it can only be memoized using utilities like lodash.memoize. In testing, the gain from this was not significant. It might make sense to revisit this when we move to a new memoization library, as mentioned in this Slack thread.
BEFORE:
Before.mp4
AFTER:
After.mp4
Fixed Issues
$ #42687
PROPOSAL: #42687 (comment)
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop