Hi all,
Just wondering if a .NET app can be compiled down to native machine code ahead of time? I'm not planning on doing so if you can, I'm just curious.
Thanks
Hi all,
Just wondering if a .NET app can be compiled down to native machine code ahead of time? I'm not planning on doing so if you can, I'm just curious.
Thanks
You can use NGen to compile it ahead of time, but this still depends on the .NET framework. Remotesoft's Salamander (a commercial app) can make a framework-less app.
ngen can be used to 'pre-JIT' an image, so it is available on disk in native form to reduce application start up time.
You CAN compile IL into native binaries. There are products that do it.
The larger question is should you...
If you want to remove all dot net dependencies to run without dot net
Basically what these products are doing is precompiling down to the machine level (x86 usually) and then statically including all the required libraries in your exe. That usually results in a HUGE exe. And, more importantly, you now don't really have the runtime on your target machine. You have a part of the runtime that the native compiler chose to incorporate.
If you want to just get a faster JIT time
You can also use NGen to compile it to a native binary, but you still have all the dependencies on dot net. Target machines still need the framework, etc.
But, when you ngen you LOSE the ability for the app to auto promote up to 64 bit. If your app is precompiled you have to force one mode. If a user is running on a 64 bit machine your IL code would have promoted (unless you flag it not to).
The JIT time is not your biggest bottleneck in most apps. It is the loading of the framework libraries and other related requirements.
If you really need it you can ngen within a setup app to get the current users target machine.
I also just recently learned that you cannot NGEN an app and expect it to take advantage of the CPU like you can with the JIT. When you run NGEN is always optimizes the output for a PentiumPro for some reason, and will not take advantage of things like SSE, SSE2, etc. So I would say that removes NGEN as a reasonable usage case.
Mono has an Ahead of Time (AOT) compiler that can emit native code.