Perf: getTransactionsSections optimization #61898
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation of Change
Problem
Switching between bottom tabs on native devices is sluggish and the performance degrades significantly for users with large amounts of data. Profiling revealed that
getTransactionsSections()
is a key bottleneck, repeatedly invoking expensive functions likegetActions()
and getTransactionItemCommonFormattedProperties()` within tight loopsWe identified several performance bottlenecks across the following functions:
getTransactionsSections
- repeated checks, unnecessary intermediate arrays (.filter().map()
), and object spreading({...transactionItem})
on each iteration.getActions
- repeated inline logic for fetching reports, permissions, and violations; unnecessary filtering of transactions.getTransactionItemCommonFormattedProperties
- redundant calls togetDisplayNameOrDefault()
and eager formatting/fallbacks.Solution
To improve performance, the following optimizations were implemented:
getTransactionsSections
-replaced.filter().map()
with afor...of
loop, moved static values outside the loop, and replaced the spread operator with direct property assignment.getActions
- split logic into helper functions and deferred expensive operations until necessary.getTransactionItemCommonFormattedProperties
- reused display names, applied lazy fallbacks, and reduced unnecessary formatting.Performance gain : For ~100 transactions, optimizations reduced processing time from about 30–40 ms down to 18–25 ms, a roughly 39% improvement.
Fixed Issues
$ #60007
PROPOSAL:
Tests
Offline tests
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectioncanBeMissing
param foruseOnyx
toggleReport
and notonIconClick
)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