Microsoft Vishal Ratna Oct 13, 2020

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

Critical Insight

By deferring non-critical initialization until after screen render, Microsoft Teams achieved double-digit improvements in Android launch performance.

The article reveals why WorkManager wasn't the answer and includes the clever Barrier pattern that makes the whole system work reliably.

About This Article

Problem

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.

Solution

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.

Impact

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.