[Android]: Report SDK size as a comment in PRs
We'd like to start managing the bundle size of the SDK more actively.
For that, we'd like to start taking some numbers during PRs, and with the end goal of posting as a PR comment the bundle size and a diff to main.
Approaches considered and characteristics of them:
Measuring the aar
- Either we do a naive measurement solely of our package without considering dependencies. Or we need to recursively find all dependencies and measure their sizes.
- There are multiple slices on each aar, for each abi.
- We'd need to compile for a specific one, or peek into the aar to calculate specific architectures.
Measuring the final app
- We can run proguard on the sample app which has heavy use of our features and measure more realistically the "overhead" in bundle size.
Suggested Phases:
- [x] Measure size of sample app
- [x] Post size as a comment to PR
- [x] Add flavor without Sentry and measure size
- [x] Post both to PR the metrics
- [x] Sizes (like JS bundle on getsentry/sentry) to PR
- [ ] Method count
- [ ] Diff (using JakeWharton/diffuse or Tencent/matrix@master/matrix/matrix-android/matrix-apk-canary)
- [x] Proguard the sample app (both withSentryAndNdk and withoutSentryOrNdk flavors)
- [ ] Document size
- [ ] For example: https://pspdfkit.com/guides/android/current/faq/framework-size/
- [x] Not having Kotlin so kotlin std doesn't affect size
Some inspiration: https://github.com/firebase/firebase-android-sdk/pull/3011#issuecomment-929768965
Worth noting that our JavaScript repo already has something like this, see https://github.com/getsentry/sentry-javascript/pull/4993#issuecomment-1110615206.
Somehow related https://github.com/getsentry/sentry-java/issues/1411
We could use https://github.com/JakeWharton/diffuse
Diffuse is a tool for diffing APKs, AABs, AARs, and JARs in a way that aims to provide both a high-level view of what changes along with important detailed output.
The first goal would be to get the output of diffuse and just add it as a comment to the PR.
Example output of diffuse:
│ compressed │ uncompressed
├───────────┬───────────┬───────┼───────────┬───────────┬────────
APK │ old │ new │ diff │ old │ new │ diff
──────────┼───────────┼───────────┼───────┼───────────┼───────────┼────────
dex │ 664.8 KiB │ 664.8 KiB │ -25 B │ 1.5 MiB │ 1.5 MiB │ -112 B
arsc │ 201.7 KiB │ 201.7 KiB │ 0 B │ 201.6 KiB │ 201.6 KiB │ 0 B
manifest │ 1.4 KiB │ 1.4 KiB │ 0 B │ 4.2 KiB │ 4.2 KiB │ 0 B
res │ 418.2 KiB │ 418.2 KiB │ -14 B │ 488.3 KiB │ 488.3 KiB │ 0 B
asset │ 0 B │ 0 B │ 0 B │ 0 B │ 0 B │ 0 B
other │ 37.1 KiB │ 37.1 KiB │ 0 B │ 36.3 KiB │ 36.3 KiB │ 0 B
──────────┼───────────┼───────────┼───────┼───────────┼───────────┼────────
total │ 1.3 MiB │ 1.3 MiB │ -39 B │ 2.2 MiB │ 2.2 MiB │ -112 B
We could also give it a try with https://github.com/Tencent/matrix/tree/master/matrix/matrix-android/matrix-apk-canary
Analyse the APK package, give suggestions of reducing the APK's size; Compare two APK and find out the most significant increment on size
diffuse github action https://github.com/usefulness/diffuse-action
Here's the relevant github action which already does an APK size diff: https://github.com/getsentry/action-app-sdk-overhead-metrics
I thought @vaind added this here, no?
not the breakdown of what changed, just the raw apk size.