views:

230

answers:

6

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

A: 

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
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
humm... good point! :D
balexandre
+1  A: 

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 Rinea
+1  A: 

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
+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 Rinea
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
+5  A: 

Yes you can: NGen.exe.

Here is a Stackoverflow discussion on NGen and ASP.NET

Chuck Conway
Now I know what NGen does :D thxs!
balexandre
NGen does nothing more than the JIT-er does except it does it in advance.
Andrei Rinea
+1  A: 

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
CIL which was formerly known as MSIL is now simply called IL.
Andrei Rinea
+3  A: 

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
You can also compile (in bytecode, not machine language) aspx files, using VS Web Deployment Projects.
giorgian
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
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 Rinea