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

2.0: iOS release build is too large (has full symbols) #1824

Closed
snej opened this issue Jul 14, 2017 · 6 comments
Closed

2.0: iOS release build is too large (has full symbols) #1824

snej opened this issue Jul 14, 2017 · 6 comments
Labels
Milestone

Comments

@snej
Copy link
Contributor

snej commented Jul 14, 2017

As @borrrden points out, the CBL binary in Release/iphoneos is currently 15.7MB, which is way too large. By comparison, the current Mac binary is ~1.6MB. The iOS binary contains 32bit as well as 64bit, and it contains the LLVM bitcode, but it shouldn't be nearly that large.

I took a quick look, and one factor is that the binary contains symbols for everything, not just for exported functions. (To check, just run nm CouchbaseLite.framework/CouchbaseLite — currently it lists 14887 lines of symbols.)

@snej snej added this to the 2.0.0 milestone Jul 14, 2017
@snej snej added the Build label Jul 14, 2017
@pasin
Copy link
Contributor

pasin commented Jul 14, 2017

@snej below is what I found (binary built from d70b7c1):

$ du -h CouchbaseLite.framework/CouchbaseLite
 18M	CouchbaseLite.framework/CouchbaseLite

$ lipo -info CouchbaseLite.framework/CouchbaseLite
Architectures in the fat file: CouchbaseLite.framework/CouchbaseLite are: i386 x86_64 armv7 arm64

$ nm -g CouchbaseLite.framework/CouchbaseLite | wc -l
     593

$ nm CouchbaseLite.framework/CouchbaseLite | wc -l
    7353

Use xcrun bitcode_strip to remove bitcode (found a command from here):

$ xcrun bitcode_strip -r CouchbaseLite.framework/CouchbaseLite -o CouchbaseLite.framework/CouchbaseLite-no-bitcode

$ du -h CouchbaseLite.framework/CouchbaseLite-no-bitcode 
6.3M	CouchbaseLite.framework/CouchbaseLite-no-bitcode

From the above result, the bitcode takes 2/3 of the size. 6.3MB seems to be reasonable to me.

@pasin
Copy link
Contributor

pasin commented Jul 15, 2017

I just noticed that the release STRIP_STYLE is set to debugging instead of non-global.
I just quickly tested building the binary with the STRIP_STYLE = non-global and the binary size is reduced to ~16MB. If stripping bitcode, the binary size is 4.9M. The result of nm CouchbaseLite | wc -l is also 593. I will run binary test to make sure that the binary works fine on Monday.

@snej
Copy link
Contributor Author

snej commented Jul 16, 2017

Interesting. You're looking at a fully-fat library with all 4 architectures, but I'm looking at just the ARM binaries in iphoneos. I'm not familiar with the process we use to merge the binaries in 2.0; does it also strip anything? Because your 4x-fat binary is much less than twice the size of my 2x-fat one and contains half the number of total symbols, so it's clearly not just a merge of the device and simulator binaries.

@pasin
Copy link
Contributor

pasin commented Jul 17, 2017

The build_framework.sh doesn't do anything special.

Build Frameworks

https://github.com/couchbase/couchbase-lite-ios/blob/feature/2.0/Scripts/build_framework.sh#L94

Merge Frameworks

https://github.com/couchbase/couchbase-lite-ios/blob/feature/2.0/Scripts/build_framework.sh#L133

I could try to see what the different between running the xcodebuild command and using the xcode. Is it possible that it could be about XCode 8.3 vs 9?

@snej
Copy link
Contributor Author

snej commented Jul 17, 2017

Wow, great discovery! I just tried defining STRIP_STYLE in the CBL xcconfig, and the MacOS binary size went from 1.74MB down to 1.36MB! That's ~380kbytes saved. (I don't know if it's worth doing this in the Mac version, but on iOS we should save a similar amount and it's totally worth it.)

pasin added a commit that referenced this issue Jul 18, 2017
This configuration will stripped all non-global symbol, as a result it helps reduce the binary size.

#1824
@pasin
Copy link
Contributor

pasin commented Jul 18, 2017

Close and open a specific one for Swift.

@pasin pasin closed this as completed Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants