Open artur-malendowicz-gain opened 5 years ago
I can confirm the issue. @rolfbjarne any culprit that we know off? @lewurm maybe you might know more info.
No adding as a bug but more of a nice too have/enhancement.
Well, It’s a bit of blocker, as it's easy to exceed max app size limit. I had to switch to some small one file solution and I am not able to use core from my mobile app.
This is a well-known problem with Newtonsoft.Json, how it uses generics does not work well with AOT-compilation and the native code size ends up quite big.
The alternative is to use other Json libraries (I know some people have had success with https://github.com/facebook-csharp-sdk/simple-json for instance, but each use case is different).
@rolfbjarne
Well, it's bad, as even you as Microsoft suggests to use Json.NET pre core 3.0...
Note that release builds of watchOS applications includes bitcode (large payload) which is submitted to Apple but is not part of the final application (as installed by users on devices)
@spouliot
But it's impossible to load it onto device if app weights 450mb...
@artur-malendowicz-gain for end-users, Apple use bitcode to rewrite the application that is sent to the watch devices.
Locally you can use Debug
(instead of Release
). It makes things much faster when developing (building and deployment).
If you really want to use Release
try adding --bitcode=marker
to the Additional touch argument of the watch app project (been a while @rolfbjarne can likely confirm). That build should be smaller (closer to the Debug
size) but can't be submitted to Apple.
@spouliot Ok, will try that.
@artur-malendowicz-gain @spouliot Just as a small data point: a small new WatchOS app that I just submitted to Apple failed their checks "The size of watch application '/Payload/your.iOS.app/Watch/your.app' (82MB) has exceeded the 75MB size limit." ... I had to enable linking of everything to bring the size down, with the fun that entails in working out what breaks as a result. My only Watch app extension dependencies are Newtonsoft.Json and Xamarin.Essentials
This is a well-known problem with Newtonsoft.Json, how it uses generics does not work well with AOT-compilation and the native code size ends up quite big.
The alternative is to use other Json libraries (I know some people have had success with https://github.com/facebook-csharp-sdk/simple-json for instance, but each use case is different).
@spouliot I just moved to SimpleJson from Newtonsoft.Json for a watch app and it made a massive difference: I no longer need to Link All
, and it was very easy to move. Thanks for this pointer Sebastien.
It also makes a big difference to the develop/deploy/debug cycle and for real users when installing from the store.
The alternative is to use other Json libraries (I know some people have had success with https://github.com/facebook-csharp-sdk/simple-json for instance, but each use case is different).
In most cases this won't help. There are too many packages that depend on Newtonsoft Json. In the best case you would have to download their code swap out Json packages, cross fingers that you won't have the update package ever again and that it has full code on the github and license that allows this. So while this may help to someone it isn't acceptable in many if not in most of the cases.
A bit of ping-pong from the same bug on Newtonsoft's github:
JamesNK commented 37 minutes ago
I don't know how Newtonsoft.Json uses generics that makes the AOT size large. Someone who knows more about Xamarin would need to investigate.
So if this is to be fixed in Newtonsoft (and that is the only solution that makes Xamarin for Apple Watch remotely usable as so many packages depend on Newtonsoft) the first step would be that @rolfbjarne explains on their github on the above issue what
how it uses generics does not work well with AOT-compilation and the native code size ends up quite big.
exactly means so that it may eventually be fixed.
@DamianMehers @ivanicin
Adding --interpret
to the mtouch arguments on the extension seems to cut the app size down by about 20%. Curious if you would be willing to test this on an older branch of your code that used Newtonsoft.Json
Is the interpret flag allowed released App Store apps? I’d assumed it was just for development. I’m afraid I’ve moved all my apps to SimpleJson
Edit: I saw @chamons note here and it looks like I may be wrong ... it seems like --interpret
is for released apps. Good stuff! Although there is a note that it can make your apps larger, so there will be a tradeoff there.
Correct, the interpreter is allowed under the App Store rules, and multiple shipping apps have submitted it successfully.
It can make your app larger, but also smaller or the same size ironically enough. IL code is smaller than assembly on average, but we have to bundle in the interpreter when you enable it. It will obviously be significantly slower at runtime, but depending on your use case it can be minor or huge.
Adding the --interpreter
flag made a pretty drastic difference for a watch app I am working on, with Json.NET as a dependency.
Steps to Reproduce
Expected Behavior
App's/AppExtension's size should increase by not that much
Actual Behavior
Newtonsoft.Json weights around 600kb in .dll. After compiling in release mode (so probably AOT has something to do) app's/appextension's size increases by around 65mb.
Environment
Build Logs
Example Project (If Possible)
Also reported in: https://github.com/JamesNK/Newtonsoft.Json/issues/2197