Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

IL2CPP slower than Mono build

Discussion in 'Android' started by ZardozJones, Jan 26, 2019.

  1. ZardozJones

    ZardozJones

    Joined:
    Dec 26, 2017
    Posts:
    5
    HI!!

    I got real problems with IL2CPP vs Mono at the moment.

    My project is a console emulator (NES), it's a test project to see how usable C#/IL2cpp is for emulators.
    C# is a superb language for emulator R&D (for multple reasons, array protections,null checks, fast delegates and tons of other reasons).

    My Unity version is 2018.3.0f2

    It's a android project, tested on a Nexus 7 2013, running droid 8.1

    I think I've optimized the core c# code pretty well to the max!
    Since it's Arm7 - most of the code is uint to avoid any byte memory read penalties.
    and tested various different build settings
    and basically mono is faster than IL2CPP!!!

    It's a bit freaky really - I would understand it, if I was using tons of unity game objects and such,
    but I'm only really using unity to blit a texture to the screen (using ongui for that).

    I'm trying to track down the direction to head with this for optimization?

    I know I can drop to native C/CPP if really needed, but I'd rather keep it pure c# code at the moment.

    NES Metroid intro screen (stable emulation code that doesn't fluctuated much).

    Average mono framerate - 53-57 fps
    Average IL2CPP framerate - 47-48 fps

    I've put in various bits and pieces I've found whilst researching optimal c# code

    [Il2CppSetOption(Option.NullChecks, false)]
    [Il2CppSetOption(Option.ArrayBoundsChecks, false)]

    and

    [MethodImpl(MethodImplOptions.AggressiveInlining)]

    for core functions e.t.c.

    I'm using Time.realtimesincestartup as my in-code profiler - which is far less intrusive than the built in profiler.

    I've noticed my core emu code runs at about 10ms, but the Unity update function runs at 18-22ms.

    Maybe there's some hidden latency with Bitmap.Apply and Bitmap.SetPixels32 ?

    any help would be awesome!
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    Initially, please make sure you are compiling the C++ code generated by IL2CPP in the release configuration, not the debug configuration (this is an option in the Player Settings).

    Beyond that, It is difficult to say what might be causing the issue. It might be worthwhile to use a native code profiler on Android to gather more data. If you can find a specific issue, we'll be happy to have a look at it.
     
  3. ZardozJones

    ZardozJones

    Joined:
    Dec 26, 2017
    Posts:
    5
    Hi Josh

    Thanks for your reply - yup I understand it's a tricky one because of the complexity of the code, and yes I've tried debug, release, master e.t.c. (btw I found no difference in code output between release and master - both produce the same code!)

    I've tried looking at the resulting IL2CPP.so with various decompiler tools (snowman e.t.c.) to find out what the issue is, but I had no luck because of name managling, release code obfuscation e.t.c.

    I suspect it's some kind of marshaling issue causing the slowdown, if I find out what the problem is - I'll post the solution here.
     
  4. Bruder

    Bruder

    Joined:
    Aug 9, 2014
    Posts:
    56
    I turned off my visus protection (AVG) and it really speed up the process (and also take much less CPU power..), no idea why...
     
  5. iagofg

    iagofg

    Joined:
    May 23, 2013
    Posts:
    5
    Problem is not compiling, problem is that running execution time is far slower. Same issue here. And because NO ARM64 support now IL2CPP seem to be mandatory... so we are doomed... even latest Unity has the same issue... for a game that moves some sprites, no problem, but for a more heavier one that ran perfectly on Mono backend, IL2CPP is death.