perf: Optimize getTransactionsSections and getReportSections#87363
Conversation
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
JmillsExpensify
left a comment
There was a problem hiding this comment.
No product review required.
| // Optimistic: works when report-action keys precede transaction keys (common case). | ||
| // resolveExportedYearFlags() re-checks after the export map is fully built. | ||
| if (!ctx.shouldShowYearExported) { | ||
| const exportedAction = transaction.reportID ? ctx.lastExportedActionByReportID.get(transaction.reportID) : undefined; | ||
| if (exportedAction?.created && DateUtils.doesDateBelongToAPastYear(exportedAction.created)) { | ||
| ctx.shouldShowYearExported = true; | ||
| } | ||
| } |
There was a problem hiding this comment.
NAB:
We might not need to call resolveExportedYearFlags to re-check via backward checking:
Idea
-
When encountering a
reportActionEntry: still buildlastExportedActionByReportID -
When encountering a
reportEntry-
add the
reportIDtoseenReportIDs -
if
lastExportedActionByReportIDalready contains thisreportIDand passes validation, then set:shouldShowYearExported = trueshouldShowYearExportedReport = true
-
-
When encountering a
transactionEntry-
add
transaction.reportIDtoseenTransactionReportIDs -
if
lastExportedActionByReportIDalready containstransaction.reportIDand passes validation, then set:shouldShowYearExported = true
-
-
Conversely, if a
reportActionEntrycomes after areportEntry/transactionEntry-
perform a backward check:
- if
seenReportIDs.has(reportID), then set both flags - if
seenTransactionReportIDs.has(reportID), then setshouldShowYearExported
- if
-
This approach could eliminate the need to loop through reportKeys and transactionKeys, but it would require an additional O(k) memory overhead, so I’m leaving it as a proposal for now.
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppandroid.hybrid.mp4Android: mWeb Chromeandroid.chrome.mp4iOS: HybridAppios.hybrid.mp4iOS: mWeb Safariios.safari.mp4MacOS: Chrome / Safarimac.safari.mp4 |
|
🚧 @luacmartins has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
✋ 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/luacmartins in version: 9.3.59-0 🚀
Bundle Size Analysis (Sentry): |
|
This PR is a pure performance refactor of internal search utility functions ( No help site changes are required. |
|
🚀 Deployed to production by https://github.com/AndrewGable in version: 9.3.59-4 🚀
|
Explanation of Change
This PR optimizes
getReportSectionsandgetTransactionsSectionsby replacing 7 iterations over dataset with a single pass that produces every derived structure at once. In addition a new computeViolationFlags() merges the two violation checks into one loop with early exit.Performance gains
Timing function execution
Span times for Home -> Reports nav and got this:
Main (11 samples): 1212 + 2273 + 1984 + 1302 + 1185 + 1224 + 1371 + 1329 + 1317 + 1244 + 1941 = 16382
Avg: 16382 / 11 = 1489.3 ms
Branch (11 samples): 1169 + 1189 + 1440 + 1246 + 1223 + 2388 + 1229 + 1941 + 1210 + 1200 + 1155 = 15390
Avg: 15390 / 11 = 1399.1 ms
Avg duration
Main 1489.3 ms
Branch 1399.1 ms
Difference -90.2 ms (~6% faster)
Fixed Issues
$ #87521
PROPOSAL: on Slack
Tests
This is a refactor, it should not alter anything apart from boosting perf.
ReportsOffline tests
Same as tests
QA Steps
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)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
MacOS: Chrome / Safari
Screen.Recording.2026-04-10.at.13.36.17.mov