-
Notifications
You must be signed in to change notification settings - Fork 546
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
Native Library - File Size Reduction? #174
Comments
same question from me. 20MB for Android is pretty heavy. thanks |
Just to note the average sizes per platform architecture:
|
I think, after looking at this, the Android is a bit large. I must have a look at what gyp is doing when it generates the project. It might be the case that the build is wrong as with Windows: mono/skia#25 |
I tried a few things, but I can't seem to reduce the size at all. Right now, it IS building release with optimizations, yet it is 15MB vs Windows's 5MB and iOS's 8MB |
it is a big difference. The realm.io guys had an interesting post on native sizes: reducing apk size, not sure if it is relevant as I haven't pulled the apk apart.. For me, between skia and a few other packages my app is a 40MB download. |
@djcparker Thanks for those links, trying some options now. |
While researching the subject, I saw this: https://groups.google.com/forum/#!topic/skia-discuss/5hNRcmERVSI |
@laarmen, thanks for that link. It was very helpful in confirming some not-so-great news. The NDK build already strips the output 😞 The actual size before stripping is ~35-40 MB and this gets stripped to ~13-16. I tried re-stripping the builds, and stripping all debug and other unused symbols, but was unable to reduce the size. |
@mattleibow |
I changed the build scripts, and managed to get an overall reduction of about 4MB on Android, 2.5MB on iOS, 2.5MB on macOS and 1MB for tvOS. Not a big drop, but the new sizes are:
@kekekeks have you been able to get smaller files? I am building and linking almost everything in: core, pdf, svg, codecs, intrinsics. |
The smallest of my buillds was 1.7MB for arm32 Android. I was not explicitly excluding anything from build, just linked unused stuff away. |
Let me look some more... i think i found that if I run strip after the build, then i can get an iOS arch from 11.5MB to 7.5MB. I need check that all works still, and nothing is getting stripped away. |
I have managed to drop iOS/tvOS quite a bit to ~5MB per arch - which is the same as Windows/UWP. macOS is a bit smaller at ~15MB per arch and Android is ~12MB per arch. As I am looking at Linux as well (#90) I notice that it is also ~16MB per arch. I still want to see why Linux/Android/macOS are so much larger, even with the same strict compile/link flags. I even made everything private and am just keeping the C API public (size did drop a bit). Basically, everything is ~5MB, except the macOS/Android/Linux builds which are ~15MB. @kekekeks were you linking in the GPU bits |
My ogirinal Linux build with GPU support was 2.6MB. |
I'm not sure that PDF was linked in. You see, I wasn't actually exposing Skia API itself, but implementing our own drawing API using Skia. So I'm sure that rendering, GPU support and font/image loading was included, but at least PDF wasn't included. On Linux I was also linking to external ZLib and libpng instead of including static ones. |
I'm no expert on elf format by any means, but i did take a quick look at the .so file for android and noticed that the .rodata section was the largest at around 7MB and code (.text) was around 4.8MB .
That seems a lot of constant data, it only looked like a few KB of text at the start of the .rodata section, no idea what the rest of it is. |
Could you guys upload an unstripped android build somewhere? I don't have a mac machine nearby. |
It looks like on linux, mac and android there is a file linked in which is 6.5MB. I assume it is something do with with unicode formatting ("externals/skia/third_party/externals/icu/android/icudtl.dat "). |
Maybe this can be used to create a more compact icu data file: |
Actually i think that online tool is for ICU57 and skia uses 56.1 currently, so this one is the correct one: http://apps.icu-project.org/datacustom/ICUData56.html There is also a project that can be used: http://download.icu-project.org/files/icu4c/56.1/icu4c-56_1-data.zip |
@Roceh Thanks for this info, I also determined that it was the icu bits. My method was: link nothing and then add bits until is jumps :) Real scientific. Anyway, I am looking at Linux right now and I think I can get a nice small build there if I use the system version. What I might do is to not include the font subsetters on the mobile devices ( |
@Roceh I am having a look and I think the size of the icu data is about 10MB (give or take). The reason I was able to shrink the Windows/UWP/iOS/tvOS to ~5MB was because they don't include the subsetter. The macOS/Android/Linux builds do. I can't use the system icu on linux as the version is not available via apt-get, so i will have to link it in. However, I don't think the size matters here since both macOS and linux are desktops, thus an extra 10MB might not be a problem. |
I think like you said it is better to remove the font subsetter, the large apk size is a large price to pay for slightly smaller PDFs, and if the iOS builds are not doing it anyway probably best to be consistent as well. |
.NET core's footprint is only 50MB, so additional 10MB might be huge. It would be nice to introduce some kind of pay-for-play system where PDF support lives in a separate package, but I'm not sure that it's even possible to build libskia that way. But linking system libecu is probably a bad idea from portability point of view anyway. |
@mattleibow awesome! Looking forward to this. Any idea when 1.56.1 will be shipping? |
@kentcb Sometime real soon, like when CI finishes. :) Well actually, it is going to take 2 hours, but I need to sleep (for 6 hours). So, if all goes well, I'll wake up to a green build and then release. It is going to be marked beta, but this is just because I want to make sure that the changes to the packaging for .net core and .net standard didn't break anyone (it shouldn't) and the the stricter linking for smaller sizes didn't exclude anything (it shouldn't have). If no-one complains in a day or so, I'll release stable - this'll also give me time to finish up the API docs for intellisense and all that. Here are some of the big and cool things from the release notes:
|
@kentcb Should be usable right now! Release Notes: https://github.com/mono/SkiaSharp/releases/tag/v1.56.1-beta |
With 15.2.2, the native bits are being embedded as a resource in the SkiaSharp assembly:
|
@kentcb - the size bloat is mentioned in #259 and links to https://bugzilla.xamarin.com/show_bug.cgi?id=53250 which is still showing as "confirmed" suggesting it hasn't been included yet... which is a right pain as my apps have bloated and I can't get the linker workaround to work properly yet... |
I can't say for sure right now, but I think this was fixed in 15.3. The regression came in due to a bug in Mono.Cecil, which was then updated for 15.3. You can try the alpha channel and test it out (and switch back if need be). |
@mattleibow nice one! Will do that when I get some time. |
Ah, thanks @djcparker @mattleibow! I've made Jon Douglas (Xamarin) aware of this because I was liaising with him yesterday on this issue. I'll report back if I can get a confirmation it's fixed in alpha. |
OK, tried switching Bitrise to alpha channel and rebuilding. Unfortunately, it still produces a bloated APK :( |
@kentcb :( not good. |
I am sure this was fixed. You should try archiving your app. It may not reduce the app size if you are running in Debug to reduce compile times, but I am able to get my app reduced if I Archive, even when I just set the linker to "Link SDK assemblies only". This is my test app: https://github.com/mattleibow/SkiaSharpDemo |
Hmmm, ok. Will try the latest alpha :) |
@mattleibow I am building with Bitrise. Prior to 15.2 my APK was ~30MB. With 15.2 and no code changes, it's now ~40MB. Cracking open the APK and looking inside shows that the native code is in two places: inside lib and also embedded as a resource inside SkiaSharp.dll. This is true of both stable Xamarin and alpha Xamarin. The bug report is CONFIRMED with no mention of a fix being in place in any channel yet. |
@kentcb If you build my sample app (https://github.com/mattleibow/SkiaSharpDemo) does the same thing happen? I can't seem to reproduce when running "Archive for Publishing". What is your IDE and your version numbers? Mine are: https://gist.github.com/mattleibow/bff95014b9cee90c828a67f1ed335fc7 |
@mattleibow I work locally with VS, but I don't use that to produce productions APKs/IPAs - they always come through Bitrise. So I'd be comparing apples to oranges if I looked at my VS output. Hmmm, I wonder whether it has to do with the Bitrise images. They've upgraded to 15.2.2, but they do not yet include VS4Mac, only XS. There's a small chance that's a factor. Bitrise plan to include VS4Mac in their images sometime in the next week or two. Once they've done that, I'll report back here as to whether that rectifies the problem. All the same, Xamarin have confirmed it is an issue, so I assume it still is. |
@kentcb I just built Release of my sample app using the stable VS and everything appears to be fine. No need for anything fancy, I just did a plain old Release build on Any CPU. I will point out that the SkiaSharp.dll in the bin folder STILL has the embedded native libraries (9MB), but the one in the .apk does not (200KB). Does my sample work for you locally in VS? And in your Bitrise build, could you send ([email protected]) the build log? I will have a look and see what is up. Here is my VS config: |
@mattleibow interestingly, my APK dropped from 45MB to 35MB again today when I merged my branch to switch us to netstandard and SDK-style csproj 🤔 |
Hello, this is crazy. using version 1.60.0, it ads 3,8 mb size while 1.60.1 adds 9mb.. what has changed in between? you didnt even increase major version number. it cant be such a big difference. see this issue |
@EmilAlipiev thanks for reporting this. The build system changed a fair bit and the stripping may have fallen back to the original settings. I opened a new issue #573 and I will see if I can get this resolved ASAP. |
Could all new comments be made on the new issue so we can track them with the next release. |
I think that size was increased also from 3mb to 5mb between 1.6x version to 2.8x version. it is not a big number but i want to just inform you :) |
So it looks like the sizes of the Skia library come to about 20 MB for Android and 13 MB for IOS. Is there any way to reduce this by creating custom builds or by another method?
Thanks,
Robert
The text was updated successfully, but these errors were encountered: