Repository navigation
perf: preload the Reports tab so the first Inbox open runs the warm path - #100042
Conversation
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
|
@DylanDylann Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
Actually, I'm not aligned with this change because it renders the Inbox tab before the user has even touched it, which is risky and could cause unexpected issues. Using One more thing, we have a fallback timer inside scheduleWhenIdle, so putting a lot of work here could keep the thread busy and affect other flows. For the preload action specifically, I also wouldn't expect it to run in the fallbackTimer. |
|
cc @mountiny for another perspective on this change |
|
Some my thoughts @DylanDylann
So the question is what fires on a mount without focus. I went through every effect in ReportsSplitNavigator, ReportScreen, ReportFetchHandler, ReportActionsList, ReportFooter, useMarkAsRead, the composer and the sidebar. useIsFocused is false for a preloaded route, and most writes already sit behind it, including composer autofocus and the keypress handler. Three writes did not. OpenReport and the first ReadNewestAction are behind isInPreloadedTab now. The only other side effect is the Pusher leaving events subscription, which fires on every ReportScreen mount today and is read only. Render cost is in the PR description: one to two renders per background message on native, zero on web once frozen.
|
|
Pushed some small fixes to make this safer.
I also merged main and measured again, 5 runs each on the same commit. With preload: 461ms average. That's 347ms faster, about 43% |
|
FYI I'm off tomorrow, coming back on Monday, try to find someone from CK to check if there is any action required |
|
I feel like that is just a general concern with the preloading and we already use that elsewhere right @WojtekBoman @sumo-slonik so technically it's not a new pattern and I am not sure how to avoid these concerns you have @DylanDylann |
We previously used preloading, but this optimization mechanism was disabled after the introduction of TabNavigator. In the past, we had to push a new SplitNavigator onto the stack for every transition, whereas now we reuse them. The screen is mounted for the first time only when navigating to a specific tab, and this PR optimizes precisely that scenario. The issue caused by the preloading mechanism is the CPU spike on web (fixed by #84025). I believe now the preloading should work better, in this version we're preloading only one tab and it happens on an idle callback. Furthermore, when I worked on this topic, I think the main disadvantage is the fact that we're not freezing the Inbox on native platforms. It costs extra memory and users might not even open that page during their session, though I don't know how common those sessions are. That said, the gain here is clear, so I'm in favor of this change 🫡 |
The 300ms starvation fallback fires even on a busy thread, so the Reports tab mount could land right where other flows were competing for it. Let callers opt out and wait for real idle.
Reviewer Checklist
Screenshots/VideosScreen.Recording.2026-09-21.at.18.54.16.mov |
|
I added the change you asked for. The preload now waits for real idle time, so it does not start from the 300ms fallback timer. Are you able to review the PR again? @DylanDylann |
|
🚧 JS00001 has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/JS00001 in version: 9.4.91-0 🚀
|
|
🤖 No help site changes are required for this PR, so I did not create a draft docs PR. This is a pure performance change. It preloads the Reports tab navigator so the first Inbox open runs the warm path. Nothing a help site reader sees changes: no new feature, no new setting, no renamed tab or button, and no copy. What I checkedEvery changed file is internal navigation, hooks, or tests — no
Read state is the one behavior worth calling out, and it is unchanged. Preloading the tab mounts I also searched If you would still like a docs PR for something specific here, tell me which article and what you want it to say and I will open one. @BartekObudzinski — you asked me to close with "please review the linked help site PR and confirm it reflects the current behavior, then mark the linked help site PR |
|
🚀 Deployed to production by https://github.com/lakchote in version: 9.4.91-3 🚀
Bundle Size Analysis (Sentry): |
| return; | ||
| } | ||
|
|
||
| navigationRef.dispatch({...CommonActions.preload(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR), target}); |
There was a problem hiding this comment.
Heads up, coming from #101938.
This preload mounts ReportsSplitNavigator with only [Inbox] and no params. When the user later taps the Inbox tab on narrow layout, React Navigation dispatches NAVIGATE Inbox to the mounted navigator, SplitRouter turns it into popToTop(), and that returns null at index 0, logging "The 'state' or 'screen' passed in the params couldn't be applied to the navigator with the screens: 'Inbox', 'Report'."
Fixed in #103746.
Explanation of Change
The Inbox tab is
lazy: true, so nothing mountsReportsSplitNavigatoruntil the first tap. That tap builds the sidebar and, on wide layouts, the centralReportScreen.This dispatches
CommonActions.preloadfor the Reports tab fromAuthScreensInitHandler, in the first idle window after the app has data. React Navigation renders a preloaded tab as iflazywerefalse, so the navigator mounts in the background and the first tap runs the warm path.Two gates hold it back:
isLoadingApphas to befalse, and the tab navigator has to have registered its state. The second one is load-bearing. A reload runsReconnectApp, which never raisesisLoadingApp, so without that gate the preload does nothing at all on a reload.Two guards skip the preload when Reports is already the focused tab or already mounted, since there is nothing to warm in either case.
On a wide layout the preloaded navigator also mounts
ReportScreen. ItsOpenReportcall marks the report read, soReportFetchHandlerholds that call while the tab is still preloaded and fires it once when the tab is opened. The first tap on a preloaded tab reuses the mounted screen instead of passing nested params, so it does not fire a secondOpenReport.Adds two span attributes,
is_preloadedandwaited_on_open_report.Results
Very heavy account, from Sentry, 24h.
ManualNavigateToInboxTabp50ManualAppStartupp50Warm re-visits stay at 52 to 62 ms on every build and platform measured, which is the control for the rows above.
The spread widens, 517 to 545 ms before against 207 to 599 ms after. The preload removes the constant mount cost and exposes the variable part. In the slowest sample the same trace carries
ManualOpenReportat 600 ms with a 477 msPOST /api/OpenReportinside it, so that tap was waiting on the network. On a wide layout the tap opens the last report, which the tab render does not control. The newwaited_on_open_reportattribute separates those from render-only navigations.Warming only the lazy chunk, with a dynamic import and no navigation preload, was tried and gave nothing: 677 ms against a 656 ms baseline, with the chunk verified warm. The cost is the mount, not the chunk. Native has no lazy boundary at all, so there the preload only warms the mount.
Cost of the background mount
A preloaded route is not frozen by
BottomTabView, which computesshouldFreezeasactivityState === STATE_INACTIVE && !isPreloaded. It is not the "keeps re-rendering while invisible" failure mode you might expect.On web the real protection is
FreezeWrapperinReportsSplitNavigator.tsx, which usesreact-freezeand the preload does not touch it.freezeOnBlurthere only setsdisplay: none. Three React DevTools recordings show zero renders inside the subtree while another tab is focused, and heap stayed flat at 145 MB over 60 seconds of Onyx churn.On native
FreezeWrapperis a no-op, so the tab does stay unfrozen until the first tap. Measured with render probes while sending messages in the background: one render on Android, two on iOS. Two renders total, not two per message.Fixed Issues
$ #100828
PROPOSAL:
Tests
Offline tests
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, 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.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