2

Is it possible to compile a ASP.NET web application to Machine language? If so, are there any performance benefits?

user161433
  • 4,419
  • 5
  • 32
  • 55

7 Answers7

7

Yes you can: NGen.exe.

Here is a Stackoverflow discussion on NGen and ASP.NET

Community
  • 1
  • 1
Chuck Conway
  • 16,287
  • 11
  • 58
  • 101
4

You can (as Charles showed in his answer), but there's no real advantage in doing so. The IL code is compiled to byte code the first time a user requests some content from your website. This is known as "Just in Time" compilation. After this step is performed, both versions of your website would have the same performance.

Adrian Grigore
  • 33,034
  • 36
  • 130
  • 210
  • You can also compile (in bytecode, not machine language) aspx files, using VS Web Deployment Projects. – giorgian Sep 02 '09 at 08:07
  • Good point, I did not know that. But how big is the performance gain for precompiling them in comparison to optimizing the database queries that have to be performed when they are executed? – Adrian Grigore Sep 02 '09 at 10:15
  • Adrian, giorgian is referring to pre-compiling ASP.NET Web Site projects just like an ASP.NET Web Application project is compiled. Nothing fancy there. – Andrei Rînea Sep 02 '09 at 16:47
2

In the end an ASP.NET Application (be it "ASP.NET Web Application" or "ASP.NET Web site") is compiled to IL and then when that piece of IL is used it is further compiled to machine code, transparently by the .NET Runtime (CLR).

The performance benefits... are there :) It works faster than interpreted web sites and so on.

If however you mean to compile its assemblies (DLLs) to native format so it can't be dissambled there are a couple of commercial tools available for both obfuscation and IL/native code replacement.

Andrei Rînea
  • 20,288
  • 17
  • 117
  • 166
2

While it is actually possible to make a .net independent executable from a .net project postbuild using tools from for example www.xenocode.com, I don't know if that holds true for ASP.NET projects, I also doubt there will be any real performance benefits after the first load of any resource.

Kris
  • 40,604
  • 9
  • 72
  • 101
  • +1! this is what I was referring to in my answer. AFAIK xenocode works for any .NET assemblies so it should work fine for ASP.NET assemblies too. – Andrei Rînea Sep 02 '09 at 16:48
  • I'm 99.9% sure that it would work, but also about 88.8% sure you won't be able to tell the difference in performance with a stopwatch. (there may be some improvement because of tighter linking between code, but i'll bet heavily against anyone noticing that). only your build process will take much longer. – Kris Sep 06 '09 at 00:27
2

If I recall correctly it is possible to do so. However, other than for academic purposes you should not pursue this idea. There is no significant speed gain to be made.

When you compile your EXE it is compiled to CIL (Common Intermediate Language). This is a platform independent format. When you launch your EXE for the first time, the .NET framework will compile that EXE into machine code for the specific machine you're running the application on. The result of this is then cached. This way, only the first launch will be a bit slower, but subsequent launches will be faster.

If you want speed gains, especially for a web application, invest your time in identifying bottlenecks in your application, like database queries etc. Also, have a look at where you could apply caching. These are way better approaches to improve performance.

Norm 2782
  • 39
  • 3
0

This is just me and without given to much thought.

a Web Application needs a Web Server to run, and that Web Server does not read Machine Code, the operating System does, and that you might think that in a Windows Environemnt...

but, then again... an EXE is already a machine code, that the .NET Framework compiled and transformed...

so ... o.O

balexandre
  • 73,608
  • 45
  • 233
  • 342
  • That is true for simple html files, not for ASP.NET projects, they are compiled into a DLL and linked into the webserver (to keep things simple) – Kris Sep 02 '09 at 07:51
0

Mono supports AOT compilation (compile to machine code); but you still need to keep around some assembly information and there are limitations in its use.

See http://www.mono-project.com/AOT for more info.

Andrew
  • 1,606
  • 1
  • 12
  • 19