getsentry / sentry-dart

Sentry SDK for Dart and Flutter
https://sentry.io/for/flutter/
MIT License
743 stars 227 forks source link

Sentry Flutter SDK is ~3 MB #2184

Closed sumanthratna closed 1 month ago

sumanthratna commented 1 month ago

Platform

Flutter Mobile

Obfuscation

Enabled

Debug Info

Enabled

Doctor

Hi all,

We're big fans of Sentry but are unfortunately might need to move away from it: we're building an iOS App Clip (which constrains us to a ~15 MB uncompressed+thinned .ipa file). Flutter is ~10 MB and Sentry is ~3 MB (which is much larger than we thought it would be), leaving us with very little room to implement actual App Clip functionality, leveraging Flutter plugins, etc.

Here's a section of the output of zipinfo -m RunnerAppClip.ipa:

drwxr-xr-x  2.1 unx        0 bx  0% stor 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/Sentry.framework/
drwxr-xr-x  2.1 unx        0 bx  0% stor 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/Sentry.framework/_CodeSignature/
-rw-r--r--  2.1 unx     2296 bX 74% defN 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/Sentry.framework/_CodeSignature/CodeResources
drwxr-xr-x  2.1 unx        0 bx  0% stor 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/Sentry.framework/Sentry.bundle/
-rw-r--r--  2.1 unx     2108 bX 81% defN 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/Sentry.framework/Sentry.bundle/PrivacyInfo.xcprivacy
-rw-r--r--  2.1 unx      757 bX 27% defN 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/Sentry.framework/Sentry.bundle/Info.plist
-rwxr-xr-x  2.1 unx  2817968 bX 72% defN 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/Sentry.framework/Sentry
-rw-r--r--  2.1 unx      782 bX 28% defN 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/Sentry.framework/Info.plist
drwxr-xr-x  2.1 unx        0 bx  0% stor 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/sentry_flutter.framework/
drwxr-xr-x  2.1 unx        0 bx  0% stor 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/sentry_flutter.framework/_CodeSignature/
-rw-r--r--  2.1 unx     1798 bX 77% defN 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/sentry_flutter.framework/_CodeSignature/CodeResources
-rwxr-xr-x  2.1 unx   219344 bX 71% defN 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/sentry_flutter.framework/sentry_flutter
-rw-r--r--  2.1 unx      797 bX 28% defN 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/sentry_flutter.framework/Info.plist

(the fourth column is number of bytes)

As you can see, Sentry is ~3 MB. Are there optimizations that can be made?

Version

8.4.0

Steps to Reproduce

  1. flutter create my_app
  2. add an App Clip target: https://docs.flutter.dev/platform-integration/ios/ios-app-clip
  3. flutter pub add sentry_flutter and call SentryFlutter.init in main
  4. flutter build ipa --release --export-method development --analyze-size
  5. open build/ios/archive/*.xcarchive
  6. "Distribute App" in Xcode
  7. "Custom" method of distribution -> "Release Testing" method for distribution
  8. select the App Clip target for distribution
  9. "All compatible device variants" for App Thinning distribution option

open the resulting directory and open App Thinning Size Report.txt and see the uncompressed size

We're happy to help on reducing the SDK size, but may need some guidance on how to approach this.

Expected Result

N/A

Actual Result

N/A

Are you willing to submit a PR?

Yes

sumanthratna commented 1 month ago

Maybe the SDK can support better tree-shaking? For us, we primarily only care about SentryHttpClient. Being able to use SentryHttpClient in our App Clip without eating all 3 MB would be amazing

buenaflor commented 1 month ago

@sumanthratna hey thanks for raising this issue.

theoretically you could do Sentry.init instead of SentryFlutter.init but you would probably miss a lot of device context, stacktrace symbolication etc...

buenaflor commented 1 month ago

do you know if there are any signifcant changes in earlier versions?

buenaflor commented 1 month ago

-rwxr-xr-x 2.1 unx 2817968 bX 72% defN 24-Jul-19 16:19 Payload/RunnerAppClip.app/Frameworks/Sentry.framework/Sentry

this is the sentry-cocoa sdk taking up space, so I'm not sure if there is much we can do from the flutter side to optimize this.

this might be an issue that could be brought up in the sentry-cocoa repo

sumanthratna commented 1 month ago

@buenaflor Thanks so much for your replies. I tried using Sentry.init instead of SentryFlutter.init and that removed the sentry-cocoa SDK from the build, which has helped us significantly -- Sentry Dart SDK is only ~0.3 MB.

Obviously, this solution is not ideal since now we don't get the features from sentry_flutter, but it's good enough for our App Clip needs. I think the ideal solution would be for Dart+Flutter to support tree-shaking native libraries, so then the Cocoa SDK could be stripped down to what we need but that's probably out of scope for you all. As a workaround, maybe splitting the Cocoa SDK into smaller SDKs with specific functionalities might allow Dart tree shaking to strip un-needed native code from the build.

Feel free to close since I don't think there are any easy solutions for this on your end.

Thanks for the help!

kahest commented 1 month ago

@sumanthratna modularizing the sentry-cocoa SDK is a long-term goal we have, but as you point out, not in the immediate scope for us. We definitely appreciate your input in any case. I'll close this issue for now, please leave a comment if there's a reason to reopen.