Strip engine code set but binary still contains unused engine code

Hi,

I’ve got “Strip engine code” set and I’m using IL2CPP, but when I examine the symbols from my final binary (i.e. when I download the DSYMs from iTunes Connect) I see things like RakNet and Colliders and physics in there, none of which I use. I’m using Unity 5.4.3f1. Is it not possible to strip these things, or was this improved in a newer version of Unity?

Thanks,
Sam

I’m not aware that these things were specifically changed to improve the strip engine code behavior, so I doubt a newer version of Unity will improve this situation.

In general, strip engine code is not perfect, but maybe it should be better in this case. If you can submit a bug report, we would be happy to investigate it. I can’t promise a resolution, bug we can have a look.

1 Like

Thanks Josh, I’ll get a bug report together.

I just realised that the RakNet symbols are coming from libiPhone-lib.a (although I’m not sure why the linker isn’t stripping those out).

Looking through the generated native C++ I see quite a large number of methods for things that I don’t use in the IL2CPP method pointer table from a variety of sources like types in the Mono base class library as well as many Unity types (e.g. BigInteger, SmallXmlParser, Hashtable, every override for the various System.Convert functions, UnityWebRequest, NetworkPlayer, Physics and Physics2D). I attached it just in case you are interested.

I guess it would be a very time consuming process to determine whether every type or method was used by a given game, although maybe it could be done in inverse - generate a list of types that are used.

I see in the Unity build log that it whitelists a bunch of things including UnityWebRequest. That one in particular has preserve set to “nothing” so I didn’t expect any of the code for it to be generated, even though it is.

3109837–235041–Il2CppMethodPointerTable.cpp.txt (1.62 MB)

I’ve reported a bug. It’s case number 921427.

Thanks!

I ended up manually stripping out methods from the method pointer table (with a post process step by patching in nulls), but it only saved around 630k. I didn’t strip out any corresponding metadata or method info data though. I guess the overhead here is not as bad as I thought. Even if I managed to strip out absolutely everything I didn’t need, I think it probably would save only about a megabyte.

It would be nice to be able to get it as lean as possible, and indeed if I were using my own engine in a native language I would only be linking in exactly what I need, but I guess it’s a small price to pay for the convenience of Unity :slight_smile: