I had a quick look at the .NET Native Preview. I am interested to see what the benefits might be. Note that currently the preview only supports 64-bit Windows Store apps.
Here is what is promised:
For users of your apps, .NET Native offers these advantages:
- Fast execution times
- Consistently speedy startup times
- Low deployment and update costs
- Optimized app memory usage
I created a small C# app that counts prime numbers using a simple approach. I created it first as a Universal App that does not use .NET Native, and then as a second app that does use .NET Native.
My initial results are disappointing. The time taken to count prime numbers is similar in both apps.
As a further test, I added code that adds the prime numbers found to a ListView control using an async task. The idea was to see if GUI interaction and multi-threading would be more revealing than simply crunching numbers in a tight loop. The apps takes much longer with this enabled, but again, there is nothing to choose between the two.
Did I really succeed in compiling the app to native code? I think so. Here are the contents of the AppX folder for the standard .NET executable:
and here for the native compiled executable – note the additional DLLs:
I am not actually surprised that there is no performance benefit in my example. JIT (just-in-time) compilation means that any .NET application is native code at runtime, though optimization might be different.
I have ended up with a much larger app to deploy, though the relative difference would be less, I imagine, with an app that contains more code.
I can also readily believe that start-up time will be better for a native compiled app, since there is no need for the JIT compiler. However my app is so small that this is not significant.
My question though is what kind of app will benefit most from native compilation? I would be interested to see guidance on this.
Of course it is also possible that later iterations of the technology will yield different results.