Improve Android App Screen Launch Times Using LazyLifecycle Callbacks
Article Summary
Microsoft Teams Android engineers faced a critical problem: heavy initialization code in lifecycle callbacks was killing app launch times. Their solution? Get lazy.
The Microsoft Teams Android team built LazyLifecycle Callbacks, a framework that defers non-critical initialization until after the screen renders. Instead of blocking the main thread during onCreate/onResume, they wait for the UI to draw before executing expensive operations.
Key Takeaways
- P95 warm launch improved 24%, cold launch improved 12%
- Uses Barrier construct to delay code until N draws or SLA timeout
- Defers RN engine warmup, telemetry, prefetches without blocking render
- Open sourced framework handles state management and concurrency automatically
By deferring non-critical initialization until after screen render, Microsoft Teams achieved double-digit improvements in Android launch performance.
About This Article
At Microsoft, over 450 Android developers were running expensive tasks during app startup. Library initialization, auth token refreshing, and service syncing all competed for CPU cycles while the screen was rendering, which delayed the first frame from appearing.
Vishal Ratna's team built a Barrier construct that holds back code execution until either N view draws finish or an SLA deadline passes. This enabled three new lazy callbacks: onLazyCreate, onLazyStart, and onLazyResume. These callbacks fire after rendering completes.
Warm launch times improved by 24% at P95, and cold launch times improved by 12% across Microsoft Teams. The framework kept state management thread-safe and removed the need for WorkManager's expensive service overhead.