2

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

7 Answers 7

7

Yes you can: NGen.exe.

Here is a Stackoverflow discussion on NGen and ASP.NET

Sign up to request clarification or add additional context in comments.

1 Comment

NGen does nothing more than the JIT-er does except it does it in advance.
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.

3 Comments

You can also compile (in bytecode, not machine language) aspx files, using VS Web Deployment Projects.
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, giorgian is referring to pre-compiling ASP.NET Web Site projects just like an ASP.NET Web Application project is compiled. Nothing fancy there.
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.

Comments

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.

2 Comments

+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.
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.
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.

1 Comment

CIL which was formerly known as MSIL is now simply called IL.
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

1 Comment

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)
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.