How We Reduced Our ANR by Three Times
Article Summary
OkCredit slashed their ANR rate by 67% and cold startup time by 70%. Here's how they debugged one of Android's most frustrating problems.
The OkCredit Android team dove deep into Android's source code to understand ANR triggers at the system level. They discovered the surprising connection between cold startup performance and background ANRs, then systematically eliminated bottlenecks across broadcast receivers, services, and the main thread.
Key Takeaways
- ANR watchdog caught slow methods better than system traces from nativePollOnce
- Background app wakeups are 2.3x slower, causing ANRs during FCM and WorkManager execution
- SharedPreferences apply() causes ANR because it blocks during onPause and onReceive
- Input dispatch ANR only triggers on next user interaction, not during the blocking operation
- Optimizing App.onCreate reduced both cold startup and background service ANRs
Critical Insight
OkCredit achieved 0.03% ANR rate by treating cold startup optimization as the key to preventing background service timeouts.