Search Unity

Resolved Expected performance of new CoreCLR vs mono vs IL2CPP

Discussion in 'Scripting Dev Blitz Day 2023 - Q&A' started by DevDunk, Feb 22, 2023.

  1. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    I have seen people talk a lot about the new c# developments and the migration to CoreCLR. Are there any early insights in what this would mean for performance?

    I have seen people talk about CoreCLR potentially being faster than or as fast as some c++ compiled code. How is performance in early tests and could it even surpass IL2CPP, or will that also see improvements, since IL would also be better.
     
    Lorrak and stonstad like this.
  2. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    We don't have yet figures to share. We did a prototype a few years ago (so with an old version of .NET Core 3.1), and the performance compared to Mono was easily around 2x times faster.

    What we have seen, outside of Unity, is that performance with CoreCLR compared to Mono should range from 2x to 10x faster. It will depend on many factors, like if your code allocates lots of managed objects or not or if your code is using some BCL functions that have been massively optimized in CoreCLR.

    Sometimes, you could find cases where the performance would not be that dramatic (e.g 10/20% faster for CoreCLR) but these cases are usually not realistic or not meaningful. For example, small functions could be optimized the same way whether you use CoreCLR, Mono, or even C++, when the code to optimize is enough simple that you can't optimize it more (e,g for example, there are enough CPU registers to optimize the code).

    This is exactly what the .NET teams have been doing in the past years while optimizing .NET 5/6/7. They have moved lots of C++ code to C# code, and because .NET has introduced CPU HW Intrinsics, they have been able to optimize things further.

    For example, recently, I ported XXHash128 to .NET 8 and the code is as fast or sometimes even, faster than C++.

    Actually, IL2CPP has never been optimized for performance. You can get relatively good performance if you perform Linked Time Optimization (LTO), but this is really painful (it can take dozens of minutes to compile/link a project). In practice, IL2CPP can be actually sometimes as slow as Mono.

    From many tests, we know that CoreCLR is definitely faster than IL2CPP. But, that being said, we hope to optimize IL2CPP with the .NET 7+ by 1) inlining more, 2) bring support for .NET HW Intrinsics, so that all the BCL code optimized in .NET 7+ would be also optimized in IL2CPP.

    In the long term, we have the dream to combine CoreCLR JIT/AOT, IL2CPP and Burst technologies to provide the best AOT experience when developing games with Unity, and we might be able also to bring this within the Editor (e.g Burst used as a Tiered Compilation with CoreCLR). We are far from there today, we are fully focused on CoreCLR, but it 's definitely something we want to improve.
     
  3. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    Thank you for the extensive reply! Really appreciated.
    Excited to see this tech come to unity in the future
     
  4. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    100
    Impressed with this explaination, as I myself am not an extremely knowledgable as to the inner workings of.Net and Mono and you've made this easily digestable. Well appreciated.