Repository navigation
perf(settings): map settings once off the main thread - #645
Merged
Merged
Conversation
settings was a cold flow: each of ~60 collectors, mostly on Main, re-ran the ~100-key mapping and the addons JSON parse on every write to the DataStore. On a cold start that showed up as 450-620 ms bursts of main-thread work outside any frame. Map once per change on Default, drop unchanged values and share the latest one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Follow-up to #644, which was merged before this commit landed on its branch.
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 moments, in code with no trace sections. A method-sampling trace of the debuggable build attributes the work outside frames toSettingsPreferences.settingsmapping (map…emit+collect+Keysinit). The same burst likely explains the freeze when opening the app after the phone sleeps: work held back while the app was frozen runs together on unlock.Change
SettingsPreferences.settingswas a cold flow. Each of ~60 collectors, mostly 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 onDispatchers.Default, skips unchanged values, and shares the latest one (shareIn,replay = 1). The type staysFlow<MiscSettings>, so callers are unchanged;first()anddrop(1)behave as before.Not verified
Compiles (Kotlin step) but has not been built into an APK or run on a device: local builds ran out of memory. Please check on device before merging: cold start, then lock for 5 min and reopen.