Exploring Future Tools: Using .NET Native for Increasing Windows Store App Performance

Traditionally, C# and VB developers enjoy the comfort and productivity of desktop application development using the .NET Framework. The introduction of .NET on non-traditional devices, such as tablets, phones and IoT gadgets, added new vector for the Framework evolution – superior performance on low power devices.

The .NET Native technology is designed to bring the performance of native code to managed code developers. Instead of generating intermediate language code, .NET Native compiles C# applications directly to native code. In addition, it statically links parts of the .NET Framework with the application and optimizes the resulting package for performance.

According to Microsoft, “popular Windows Store apps start up to 60% faster and use 15-20% less memory when compiled with .NET Native.” Let us see how performance will improve for an average app.

Currently .NET Native is focused on Windows Store apps and is available as a preview. For the performance test, I will use one of my published Windows Store apps – Toronto CHEMTrack – and Visual Studio “14”.

How to enable .NET Native

Enabling of .NET Native for Windows Store app includes three steps:

1. AnyCPU configuration is not supported by native compiler, so x64, x86 or ARM architecture shall be used.

clip_image002

2. Enable .NET Native for the project.

clip_image004

This step triggers analysis of the project to verify that the code is compatible with .NET Native. It also creates “default.rd.xml” to inform .NET Native about important parts of metadata that should be retained during compilation. For simple cases, default configuration is enough for functioning properly.

3. Enable .NET Native compiler in the project properties

clip_image006

Compilation will take longer than before but the resulting app will be generated using .NET Native compiler.

Performance comparison

MSDN provides a great overview on measuring app startup performance. This method include use of EventSource to instrument the application:

clip_image002[6]

App.xaml.cs

image

MainPage.xaml.cs

image

And use of PerfView to monitor events:

clip_image002

Applied to Toronto CHEMTrack, with and without .NET Native, it generated six data points to analyze.

clip_image004

The following table demonstrates impressive performance improvement for application compiled using .NET Native:

 

Managed, ms

.NET Native, ms

Perf. improvement

App started

0

0

N/A

App initialization

356.159

76.506

78.52%

MainPage initialization

531.561

42.095

92.08%

MainPage load

145.756

45.367

68.87%

Try It

Have you tried .NET Native with your apps yet? Leave a comment and let me know what your performance gain is. If not, after seeing the numbers above, I am hoping that you will give it a try.

Connect(); on November 12 and 13

clip_image001A cloud-first, mobile-first, developer-first , virtual eventDon’t miss Connect(); next week! Scott Guthrie, S. Somasegar, Brian Harry, and Scott Hanselman will take the stage to show innovative, new Microsoft products, services, and technologies including .NET, Azure, Visual Studio, and Visual Studio Online.

Dive deeper into the technical details behind the announcements with over 40 on-demand technical sessions. Interact with the Microsoft engineering teams in live sessions to get answers to your questions.
Come experience the new world of mobile-first, cloud-first development where you will build on your existing skills to unleash your creativity in the comfort of your office.

Check out the Connect(); for more details >>