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! |
aimane-chnaif
left a comment
There was a problem hiding this comment.
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 |
mountiny
left a comment
There was a problem hiding this comment.
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 Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop