Bug 21599 - BugSense package not properly linked?
Summary: BugSense package not properly linked?
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: 7.2.6
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-07-25 11:56 UTC by Christian Rishøj
Modified: 2016-05-25 00:22 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Sample project (7.37 MB, application/zip)
2014-07-30 02:32 UTC, Christian Rishøj

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Christian Rishøj 2014-07-25 11:56:01 UTC
Description of Problem:

Including the BugSense package in a Xamarin.iOS project has an unproportional impact on the app size, as measured by "estimated App Store size" of the app archive in Xcode's Organizer. 

Hypothesis: The Xamarin linker does not properly prune unreachable code from BugSense and dependent packages.

Steps to reproduce the problem:
1. Create a default "Single View" iOS project
2. Create an archive for "iOS Device" under the "Release" configuration
3. Observe the "estimated App Store size" in Xcode's organizer:
      Approx. 2.7 MB
4. Add the BugSense iOS package from Project > Add Packages...
5. Create a new archive
6. Observe that the "estimated App Store size" in Xcode's organiser has now exploded:
      Approx. 13.6 MB

Expected Results:

BugSense doesn't do much, so I had not expected such a massive impact on app's size.

How often does this happen? 

Consistently when BugSense is added from the menu item Project > Add Package. I have not tried to add the Dll's manually.
Comment 1 Christian Rishøj 2014-07-26 02:55:18 UTC
I've now tried both including BugSense as a package (NuGet), and the "old-school" way of adding assemblies myself. Empirically, this does make a difference for the final app size:

- minimal, single-view iPhone app, no references to BugSense: 2.7 MB
- BugSense added as package, but InitAndStartSession not called: 3.2 MB
- BugSense added as package, and InitAndStartSession called: 13.6 MB
- BugSense added as assemblies, but InitAndStartSession not called: 2.7 MB
- BugSense added as assemblies, and InitAndStartSession called: 8.4 MB

Something about the package/NuGet integration smells funky. It could seem like it interferes with the Xamarin linker's ability to prune unreachable code.

Direct download of the BugSense assemblies:
Comment 2 Sebastien Pouliot 2014-07-28 09:50:37 UTC
You're right that NuGet integration _should_ not change the final binary size, so something looks wrong.

NuGet integration is part of Xamarin Studio, not Xamarin.iOS, can you provide all your version details ?

The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 3 Christian Rishøj 2014-07-29 02:12:22 UTC
I've just switched to the alpha channel in order to test some iOS 8 stuff. However, the issue in question occurred before the switch, with the latest stable. 

At any rate, here's my current version details:

=== Xamarin Studio ===

Version 5.2 (build 384)
Installation UUID: a2c3ebba-03b0-42fb-a504-a5d1b522dea9
	Mono 3.6.0 ((no/f540f8a)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 306000039

=== Apple Developer Tools ===

Xcode 6.0 (6194.21)
Build 6A215l

=== Xamarin.Mac ===


=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 0ba5e04
Build date: 2014-07-01 17:06:51-0400

=== Xamarin.Android ===

Not Installed

=== Build Information ===

Release ID: 502000384
Git revision: 09e06441e39ea272ddda63758fd53013157f7e45
Build date: 2014-07-16 11:15:54-04
Xamarin addins: 2d11dd4dad5b35ca83f24d70e965792a47be8291

=== Operating System ===

Mac OS X 10.10.0
Darwin Christians-MacBook.local 14.0.0 Darwin Kernel Version 14.0.0
    Wed Jul 16 00:46:31 PDT 2014
    root:xnu-2782. x86_64
Comment 4 Sebastien Pouliot 2014-07-29 11:50:49 UTC
I do not see a size difference between [no | package | assemblies] when bugsense is not used in the application. IOW the .app size remains identical (as expected).

OSX's finder reports every .xcarchive files to be 7.7MB while the *estimated* content size (from Xcode 6) shows 3MB for each of them. 

note: I cannot say how Xcode computes this number (but it's known not to be very accurate).

When I enable (call) BugSense I still get identical numbers (assemblies or package). The .app is 15.3MB and Xcode estimates is  14.6MB.

I'm not sure how you got this size difference, maybe it's just the *estimated* size (Xcode) that differed (and not the .app).

If you can still duplicate this (difference in .app size, not estimated size) please attach the different projects to the bug report. Maybe I did not end up using the same packages/assemblies as you have (but I can't see how it would make a difference).

Now for the size difference, with/without BugSense, comes from:

* it needs to add it's own, native static library (near 2MB, some of it might be removed by the native linker);

* the provided .NET API requires a lot more code, it refers to Newtonsoft.Json (407kb) and SystemServicesBinding.dll (2.5MB). Those are not, by default (linksdk), processed by the managed linker so they add a lot of code in the final app;

* those assemblies recursively requires more of the BCL (e.g. like: System, System.Core, System.Xml, System.Xml.Linq...) as part of the application (they are linked, so they are not completely added, but it still represent a lot of additional code;

* The template app itself (without bugsense) does not require any of the above (only mscorlib and monotouch.dll assemblies) so it's a lot smaller;

> BugSense doesn't do much, so I had not expected such a massive impact on app's
> size.

It's huge. However part of the extra BCL code being added would (very likely) be part of most applications you would write anyway. As such the final "extra" size for a complete application would be less then the current 10MB. YMMV
Comment 5 Christian Rishøj 2014-07-30 02:19:18 UTC
With the alpha channel Xamarin, I get identical sizes for 
* baseline,
* package without calling, and
* assemby without calling.

However, I still see a significant difference in size (both .xcarchive, .app and Xcode estimated) for
* package with calling (15M .app), and
* assemby with calling (9M .app).

I'm attaching my sample project. It is currently configured with the package, which results in a 15M .app here. In order to reproduce the 9M .app, simply remove the packages (BugSense + NewtonSoft), and add references to the assemblies in the "BugSense" folder.
Comment 6 Christian Rishøj 2014-07-30 02:32:49 UTC
Created attachment 7530 [details]
Sample project
Comment 7 Sebastien Pouliot 2014-07-30 09:58:46 UTC
Using your project I get a .app of 15.3MB. I also get the same size if I modify it to remove the package and add manual references (to all the assemblies that the package provide).

My guess is that you're not building against the _every_ assemblies from the package, and that makes one of the binding libraries (e.g. SystemServicesBindings.dll*) not the be part of the final .app. If you're sure your projects were identical then please attach your assembly-based project (and I'll build/compare it with the previous one)

* I do not know if BugSense will work properly without it

It turns out SystemServicesBindings.dll is also a binding library (so removing would requires much less space). I _assume_ it's part of the BugSense package for a valid reason (i.e. required at runtime).

Sadly neither SystemServicesBindings.dll or BugSense.Xamarin.Bind.iOS are using SmartLink** so you they do not help much the (Apple native) linker to remove unused _native_ code from them.

** again I'm not sure if SmartLink can be used with BugSense (e.g. if it dynamically loads native code)

more details about SmartLink in http://stackoverflow.com/a/16471086/220643
Comment 8 Sebastien Pouliot 2016-05-25 00:22:23 UTC
Results were never duplicated locally, but some answers were given. 

If you are still experiencing this issue please provide all the requested information and re-open the bug report. Thanks!