Skip to content

perf: fix launch freeze (settings flow on main, off-screen tabs) - #644

Merged
Sahank29 merged 1 commit into
mainfrom
fix/defer-offscreen-tabs
Nov 15, 2026
Merged

Sahank29 merged 1 commit into
mainfrom
fix/defer-offscreen-tabs

Conversation

@Sahank29

@Sahank29 Sahank29 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A user reported the app freezing for 3–4 s on launch, plus stutter when the feed auto-refreshes.

On a CPH2649 (Snapdragon 8 Elite, release build), every cold start had 3 frames of 450–700 ms. Frame stats put all of that time before the frame starts (vsync → HandleInputStart), not in drawing. A scheduler trace shows the main thread running flat out for 439, 624 and 520 ms at those exact moments, in code that emits no trace sections. A method-sampling trace of the debuggable build attributes the work outside frames to SettingsPreferences.settings mapping (map…emit + collect + Keys init) and to BotGuard's WebView creation.

Changes

  1. SettingsPreferences.settings: this was a cold flow. Each of ~60 collectors, most on Main, re-ran the ~100-key mapping and the addons JSON parse on every write to the DataStore. It now maps once per change on Dispatchers.Default, skips unchanged values, and shares the latest one (shareIn, replay = 1). The type stays Flow<MiscSettings>, so callers are unchanged; first() and drop(1) behave as before.
  2. MainShell pager: Statistics and Playlists were composed on the launch frame and started their own loads. They are now composed once the user first leaves the Feed, then kept composed as before, so a dock jump back to Feed still never rebuilds it.

Measured

Change 2, non-debuggable bench build, OnePlus Pad, 5 cold starts each:

main-thread CPU (first 12 s) frames ≥ 100 ms
main 916 ms avg 4.2
change 2 744 ms avg (−19%) 3.2

Change 1 compiles but has not been run on a device (local builds ran out of memory). Please check it on device before merging.

Not covered

  • Player-open stutter. On the CPH2649 every open has 2–4 frames of 30–45 ms while the app is still verify-compiled. After cmd package compile -m speed-profile there are 0 frames over 16 ms. So it comes from running without AOT after each sideloaded update, until Android's background dexopt applies the baseline profile. No code change here.
  • Return after a few minutes. FeedViewModel.onVisible() refreshes after 90 s and the feed is rebuilt for each of 3–4 progressive updates. Unchanged; a repro on the CPH2649 showed one 53 ms frame.
  • Reported crashes. No diagnostics file.

Statistics and Playlists were composed on the launch frame and started
their own loads, recomposing off-screen while the Feed did its first
load. Compose them once the user first leaves the Feed, then keep every
tab composed as before so a dock jump back never rebuilds the Feed.
@Sahank29
Sahank29 merged commit 4d10c15 into main Nov 15, 2026
1 check passed
@Sahank29 Sahank29 changed the title perf(shell): compose off-screen tabs after leaving Feed perf: fix launch freeze (settings flow on main, off-screen tabs) Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant