Skip to content

perf: optimize startup without functional change (#99 #100 #101 #102) - #104

Open
shreyashp47 wants to merge 5 commits into
mainfrom
experimental
Open

shreyashp47 wants to merge 5 commits into
mainfrom
experimental

Conversation

@shreyashp47

Copy link
Copy Markdown
Owner

Summary

Optimize app startup without functional change. Addresses performance audit (cold start → first frame / TTI) while keeping all user-visible behavior identical.

Branch: experimental → main
Closes #99, #100, #101, #102 ( #103 deferred to follow-up — needs emulator for BaselineProfile generation).

Changes

#99 — Eliminate main-thread blocking in attachBaseContext

  • app/src/main/java/com/shreyash/dotrack/DoTrackApplication.kt:20-46 — getLanguageCodeSync() now reads SharedPreferences(dotrack_sync_prefs) (~1ms) instead of runBlocking { dataStore.data.first() } (30-150ms). DataStore remains source of truth.
  • data/src/main/java/com/shreyash/dotrack/data/repository/UserPreferencesRepositoryImpl.kt:239 — dual-write language to sync prefs on setLanguage.
  • DoTrackApplication.onCreate async migrates existing DataStore value to sync prefs (one-time for upgrades).

#100 — Fix StartupProvider misconfiguration

  • app/src/main/AndroidManifest.xml:22 — correct provider tools:node="merge" removing WorkManagerInitializer + EmojiCompatInitializer. WorkManager is provided via DoTrackApplication : Configuration.Provider.
  • Verified merged processDebugMainManifest now only ProcessLifecycleInitializer + ProfileInstallerInitializer (was 4).

#101 — SplashScreen for perceived startup

  • gradle/libs.versions.toml:15 + app/build.gradle.kts:91 — androidx.core:core-splashscreen:1.0.1
  • app/src/main/res/values/themes.xml:10 — Theme.DoTrack.Splash (postSplashScreenTheme → Theme.DoTrack, background @color/splash_background)
  • app/src/main/java/com/shreyash/dotrack/MainActivity.kt:73 — installSplashScreen() before super.onCreate, app/src/main/res/values/colors.xml new splash_background #7C3AED.

#102 — Startup cleanup (actual TTI)

  • app/src/main/java/com/shreyash/dotrack/core/util/WallpaperGenerator.kt:47,58 — wallpaperManager by lazy, formatters cached, 7 DataStore reads now concurrent via async/coroutineScope (was sequential).
  • data/src/main/java/com/shreyash/dotrack/data/di/DatabaseModule.kt:27 — addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4) instead of fallbackToDestructiveMigration() (aligns with TaskDatabase.kt:57).
  • core/src/main/java/com/shreyash/dotrack/core/ui/theme/Theme.kt:72 — remember caches dynamicColorScheme + priorityCardColors, removed SideEffect global mutation; app/src/main/java/com/shreyash/dotrack/ui/tasks/TaskComponents.kt:80 now uses LocalPriorityCardColors.
  • data/src/main/java/com/shreyash/dotrack/data/util/DateTimeConverters.kt:7 — formatter to companion object.
  • app/src/main/java/com/shreyash/dotrack/ui/tasks/TasksViewModel.kt:98 — single tasksResultFlow shared upstream (taskCounts derived, single Room observer instead of 2).
  • app/src/main/res/xml/task_widget_info.xml:8 — updatePeriodMillis 300000 → 0 (rely on TaskWidgetUpdater).

No functional change

  • Locale still applied on <13 via attachBaseContext, 13+ via LocaleManager in SettingsViewModel.
  • Sorting/filtering, wallpaper generation, widget updates, deep links, dark mode all preserved via TaskSorter/CompositionLocal.

Testing

  • ./gradlew assembleDebug — BUILD SUCCESSFUL
  • ./gradlew testDebugUnitTest — 27 tests pass (TaskSorterTest 7, SettingsViewModelTest 14, TasksViewModelOrderingTest 5)
  • Merged manifest verified no WorkManagerInitializer/EmojiCompatInitializer
  • No connectedAndroidTest run (needs emulator); Macrobenchmark deferred to [Perf] Add Baseline Profiles + startup tracing + indexing #103

Estimated improvement

Follow-up

cc @shreyashp47

- #99: eliminate runBlocking DataStore in attachBaseContext
  DoTrackApplication.getLanguageCodeSync now reads SharedPreferences
  sync cache (dotrack_sync_prefs) instead of runBlocking dataStore.first();
  UserPreferencesRepositoryImpl dual-writes language to sync prefs;
  Application.onCreate migrates existing DataStore value async
- #100: fix StartupProvider removal - WorkManagerInitializer and
  EmojiCompatInitializer now correctly removed via provider merge;
  verified merged manifest only keeps ProcessLifecycle + ProfileInstaller
- #101: add SplashScreen API (androidx.core:core-splashscreen 1.0.1)
  Theme.DoTrack.Splash + installSplashScreen() in MainActivity for
  perceived startup 200-400ms, postSplashScreenTheme -> Theme.DoTrack
- #102: startup cleanup
  * WallpaperGenerator wallpaperManager by lazy, dateFormatter companion,
    7 prefs reads now concurrent via async/coroutineScope
  * DatabaseModule uses addMigrations(MIGRATION_1_2,2_3,3_4) instead of
    fallbackToDestructiveMigration()
  * Theme: cache dynamic colorScheme + priorityCardColors with remember,
    remove SideEffect global mutation; TaskComponents now uses
    LocalPriorityCardColors
  * DateTimeConverters formatter to companion object
  * TasksViewModel single tasksResultFlow shared upstream, taskCounts
    derived from same flow (single Room observer)
  * Widget updatePeriodMillis 300000 -> 0 (rely on TaskWidgetUpdater)

No user-visible behavior change, assembleDebug + testDebugUnitTest green

Experimental branch for startup work
@shreyashp47 shreyashp47 added the enhancement New feature or request label Sep 13, 2026
shreyashp47 and others added 4 commits September 13, 2026 14:20
…ontext cast

Fixes Build and Deploy failure on experimental@01e7ab0
/app/src/main/java/com/shreyash/dotrack/MainActivity.kt:117 lint error
Use androidx.activity.compose.LocalActivity.current

Verified locally, no functional change
Previous beta track already has 53 (run 30335669059), so increment to unblock experimental beta deploy
…lay beta

Main advanced to 1.55 via 3 automated bumps (53,54,55) while experimental was on 1.53 - merge to sync version, next beta will be 1.56/56

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Perf] Eliminate runBlocking DataStore read on main thread in attachBaseContext

2 participants