Mono vs IL2CPP o_O

Hi ive just spend two days optimizing game code, preloading assets. Preinitalize some GUI Prefabs. Optimizing blocksRaycast. Adding more Canvases to minimize potential redraws.

I optimized everything. 1000-800 stable fps in the editor (2019.4) Overoptimized.

It was inside the main game scene, after the player won, the camera zoomed in and the successgui was popping in.
Shit lagged noticeable on android. The Zoom made it visible. Did this always lag?

After splitting the code up and testing every single part i realized. Everything lags - how could anyone have ever develop anything with unity.

Then i switched to IL2CPP and… load times x5. Not a single lag. No first touch lag. No tooltip lag. Faster scene loading.
Wtf? Was Mono always that incredible slow? Is Mono only for testing?
I have always used Mono since ive read of those crash problems on android in 2018.

Mono uses JIT, which means it compiles the dotnet bytecode into native CPU instructions on-demand. This means there can be CPU spikes when code is compiled for the first time during execution, and since it has to compile at run time there are certain limitations to how much it can optimize the generated code.

Also, Unity’s implementation for Mono on Android only supports 32-bit ARM, and now that Google requires all apps to also support 64-bits you have to use IL2CPP. This means the only platforms where you can actually still ship games using Mono are Windows, Linux, and Mac. I think you can still build for PS4 and Xbox using mono with 2018.4, but not in 2019 and newer.

2 Likes

oh that makes sense. thanks for your replay.

so… in mono you should preexecute code so it wont recompile on the first try?
im having a strong phone - galaxy s8 and it still causes a lot of lags in a simple 2d game.
was that always the case?
i mean i wont use it anymore, but mono was the main scripting backend for a long time and i find it hard to believe that it had such bad performance even back then

There are a couple forum posts about how people found out that pretty much every math function in Mono first converts the float parameters to doubles before performing the operations, then converts the result back to float, which can be terrible for performance.

But it converts to double explicitly (programmer intention) or the cpu or JIT decides to operate on double instead of float ?