bugsnag / bugsnag-android

BugSnag crash monitoring and reporting tool for Android apps
https://www.bugsnag.com/platforms/android/
Other
1.19k stars 205 forks source link

Rework startup to not block on all background tasks #2061

Closed lemnik closed 3 months ago

lemnik commented 3 months ago

Goal

Avoid blocking the main thread during normal startups.

Design

Previously in order to avoid [StrictMode]() violations the notifier would run most IO related work on a background thread. However these background tasks would be immediately awaited by the main thread, which has the side-effect of blocking the main thread anyway.

This PR changes all of the "results" objects into Futures such that the main thread will continue processing until the background task result is actually required. There are several StrictMode violations remaining, most of which are from retrieving the Context.filesDir and cacheDir (both of which stat on the main thread). These will be corrected in a future PR into this integration branch which will improve the use of background tasks further.

Changeset

Replaced all of the background task results with Future objects, so that each can be awaited when it is required.

Testing

Modified existing unit tests to handle the new startup sequence.

bugsnagbot commented 3 months ago

Android notifier sizes

Format Size impact of Bugsnag (kB) Size impact of Bugsnag when Minified (kB)
APK 1851.58 1674.82
arm64_v8a 631.04 450.82
armeabi_v7a 565.51 385.29
x86 704.75 528.62
x86_64 676.09 495.86

Generated by :no_entry_sign: Danger