Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry Flutter SDK is ~3 MB #2184

Closed
sumanthratna opened this issue Jul 19, 2024 · 13 comments
Closed

Sentry Flutter SDK is ~3 MB #2184

sumanthratna opened this issue Jul 19, 2024 · 13 comments

Comments

@sumanthratna
Copy link

sumanthratna commented Jul 19, 2024

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
Copy link
Author

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
Copy link
Contributor

buenaflor commented Jul 20, 2024

@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
Copy link
Contributor

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

@buenaflor
Copy link
Contributor

-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
Copy link
Author

@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!

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jul 22, 2024
@kahest
Copy link
Member

kahest commented Jul 23, 2024

@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.

@kahest kahest closed this as not planned Won't fix, can't repro, duplicate, stale Jul 23, 2024
@github-project-automation github-project-automation bot moved this from Needs Discussion to Done in Mobile & Cross Platform SDK Jul 23, 2024
@buenaflor
Copy link
Contributor

@sumanthratna we have released sentry-dart/flutter8.9.0 which allows you to have stacktrace symbolication with only using Sentry.init on iOS, macOS and Android. Please try it out.

@johannesvuorinen
Copy link

@sumanthratna we have released sentry-dart/flutter8.9.0 which allows you to have stacktrace symbolication with only using Sentry.init on iOS, macOS and Android. Please try it out.

Tried Sentry.init instead of SentryFlutter.init in our App Clip but I cannot anymore get anythin visible in the sentry website. Not even in releases. With SentryFlutter.init it works.

await Sentry.init( (SentryOptions options) { options.dsn = ConfigDefs.FM_SENTRY_DSN; options.environment = ConfigDefs.getEnvironmentNameForSentry(); options.release = getReleaseNameForSentry(); }, appRunner: () => runApp( const MyAppClip(), ), );

@buenaflor
Copy link
Contributor

Do you mean you can't get issues to show up?

There are some limitations though since Sentry.init doesn't support release health compared to SentryFlutter.init but that shouldn't affect your issue

@johannesvuorinen
Copy link

Do you mean you can't get issues to show up?

There are some limitations though since Sentry.init doesn't support release health compared to SentryFlutter.init but that shouldn't affect your issue

Yes - I cannot seem to see issues. Assuming the exceptions and error logs should appear normally from Flutter? And yes in "Releases" I cannot see either

@buenaflor
Copy link
Contributor

Okay got it, that does not seem right, errors should show up in your sentry issues list.

could you enable debug and paste some of the logs?

@buenaflor
Copy link
Contributor

@johannesvuorinen which sentry dart version are you using?

@johannesvuorinen
Copy link

I am using the latest one and finally found the reason. This was needed:
options.httpClient = CupertinoClient.fromSessionConfiguration(URLSessionConfiguration.defaultSessionConfiguration());

Apple disallows different things in App Clips like sockets so devs need to use Apple's own network framework which the cupertino_http package enables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Archived in project
Development

No branches or pull requests

4 participants