Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Mono vs IL2CPP

Discussion in 'Editor & General Support' started by Tech_N_Gamer, May 28, 2018.

  1. Tech_N_Gamer

    Tech_N_Gamer

    Joined:
    Nov 9, 2016
    Posts:
    38
    So I've been noticing that IL2CPP has been showing up more and more and Mono showing up less and less. And from research that I'm doing, it seems that IL2CPP seems to be better but compile times are slow. So, is it better to use IL2CPP over Mono, and why? Also, why is IL2CPP becoming so pronounced over Mono? Another thing, don't know where to put these questions so I'm putting them here.
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    5,521
    There are a number of trade-offs in both directions. The two scripting backends are different - your choice depends on your use case. Here is a far-to-brief overview:

    Ahead-of-time (IL2CPP) vs. JIT (Mono) compilation:

    Compile times for AOT are longer, but the binary is completely specified when you ship a game. JIT compilation is faster, but compilation to machine code occurs on the end user's device (many platforms are AOT-only, so you may not have a choice). JIT is more flexible - you can use more of .NET, where AOT is faster for some cases (e.g. IL2CPP is better at floating point math than Mono).
     
  3. Mazak

    Mazak

    Joined:
    Mar 24, 2013
    Posts:
    225
    Can we expand on this difference?

    IL2CPP has been in works for several years.

    What about libraries?

    I use several external libraries how are these .NET libraries effected?
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,967
    sj631, PutridEx and OneSketchyGuy like this.
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    5,521
    IL2CPP should work fine with any library that works with an AOT platform. If if the library uses dynamic code generation (via System.Reflection.Emit), it won't work with IL2CPP.

    In general, IL2CPP correctly converts and runs any .NET code from C# (we don't support F#, for example) - modulo bugs, of course (but we try to fix those pretty fast).
     
  6. Waz

    Waz

    Joined:
    May 1, 2010
    Posts:
    273
    I've tried IL2CPP a couple of times but always run into unimplemented functions. For example,

    IL2CPP does not support FileSystemWatcher for some reason.

    IL2CPP does not support marshaling delegates that point to instance methods to native code, so Facepunch.Steamworks doesn't work with it.

    So while YMMV, I measured it more in yards than miles.
     
  7. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    567
    I am programmer in learning :), so not too experienced with what goes on in the back end...

    In simple terms, as of 2018.2.x can I set my project (building for windows 10) .Net 4.6 and IL2CPP and move on? In other words is there a reason NOT to use 4.6/IL2CPP?

    Thanks!
     
    Last edited: Jan 14, 2019
  8. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    27,826
    There is no reason to avoid using IL2CPP unless you're doing some weird runtime wizard nonsense (reflection) or you need to have faster build testing cycles and your code changes a lot

    Further details:
    https://docs.unity3d.com/Manual/IL2CPP.html
     
  9. Thre3ouls

    Thre3ouls

    Joined:
    Apr 13, 2016
    Posts:
    22

    The reason is that IL2CPP does not support marshaling delegates that point to instance methods to native code, so Facepunch.Steamworks doesn't work with it.

    So if you have a fix for this please let us know.
     
    daisySa likes this.
  10. hassonhamo3

    hassonhamo3

    Joined:
    May 25, 2018
    Posts:
    39
    i'm publishing my game to android platform , which one should I go for ? I've tried both and didn't see any difference :)
     
  11. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    27,826
    IL2CPP is always faster, so it will likely assist on slower devices. For further performance I would recommend gpu optimisations.
     
    IgorAherne likes this.
  12. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,538
    IL2CPP seems to extend the time it takes to build by.... a lot. I don't think it can be understated just how much slower IL2CPP is than Mono. Which makes sense - cpp is a lot slower to compile than C#, and you also have the whole conversion step in there.

    My experience has been that it's not viable to use IL2CPP to produce builds for testing without a build server. It's also deeply problematic for profiling - you should profile builds, but when builds takes 30 minutes to and hour (or longer), checking if a single change makes a difference for runtime speed becomes a several hour project.

    The manual says:
    "Tip: You should use IL2CPP to both develop and ship your Project. If iteration times end up being too slow using IL2CPP, switch temporarily to the Mono Scripting Backend during development to improve iteration speed."

    I think that "if" could safely be changed to "when".
     
  13. charlie_sbg

    charlie_sbg

    Joined:
    Dec 18, 2016
    Posts:
    13
    The elephant in this room seems to be build size. I went up 12.7 MB! I'm still looking into this, if some engine stripping works I can possibly drop that to an expansion of 7.9 MB. That's still sizable. This is a typical free-to-play mobile game with puzzle and meta game.

    The trade-off is supposed to be that it loads and runs faster. But my iOS experience (which has been il2cpp for years) is, eh, not so much.

    So I can't complain because Unity is a great tool. But it's hard to polish the cost here. Hopefully it pays off somehow.
     
  14. wuhaiquan

    wuhaiquan

    Joined:
    Aug 30, 2019
    Posts:
    1
    every platform(armebi-v7a/arm64/x86) will generate a libil2cpp.so, have any suggestion to handle it?
     
unityunity