ASP.NET 'always compiling'. Noob question
I was talking to a guy and he says he likes his site with asp but not asp.net because its 'always compiling'. I Know aspx is compiled and is separate from the mai开发者_如何学Cn app in a dll. But what does he mean by 'always compiling'? I thought it compiles once on startup and everything you modify aspx file if you modify at all.
But anyways, how is the performance of server side ASP.NET compared to others such as php, python, ruby and java?
You're right, ASP.NET dynamically compiles ASPX web pages and caches the generated binaries when a page is hit after one of the following events:
- the IIS application pool has been recycled
- a change is made in the
bin
folder - a change is made in the
Web.config
file
This dynamic compilation stage comes naturally with a price in terms of page responsiveness. However it affects only the first request coming in to a specific page while it represents an performance enormous benefit for the following requests, since they are served a cached compiled version of the page.
The performance penalty paid by the first page request can be mitigated by performing the ASP.NET compilation and caching step ahead of time. This technique is known as web site precompilation and is done through a command-line tool included in the .NET Framework called ASP.NET Compilation Tool (Aspnet_compiler.exe).
Related resources:
- Understanding ASP.NET Dynamic Compilation
- ASP.NET Web Site Precompilation Overview
Very generally....
The "code behind" file is compiled in advance which would generally contain most of "your" code.
The aspx itself it also compiled, but usually not in advance which is probably his reason for saying "always compiling". Each page is compiled as required and the compiled version is cached in temp files until it needs to be compiled again.
'always compiling' of asp.net is possible in some cases - if website have rare requests and application pool's idle time-out(in iis) is very short(1 minute for example). You can note that first request takes long time(about even few seconds), but after first compile it asp.net runs very fast.
speed tests - http://www.wrensoft.com/zoom/benchmarks.html
Since asp (not ASP.NET) is a script language like php everything compiles every time.
In ASP.NET you have to differentiate between presentation items (aspx pages/views) and pure code items (classes/code behind etc).
In general compilation in .NET means compiling code into IL (Intermediate Language or more generally speaking: byte code).
When such a compiled component is actually used it compiles again into actual machine code.
This process is called 'Just In Time' (JIT) compilation.
Presentation
The presentation pages are compiled the first time they are accessed. But your web server notices when they are modified and recompiles them again.
Code Code items in fact only get compiled once. At the time you hit build in VS.
So what does that mean performance wise? Well think about it, which is further the way from user readable code to machine code or from byte code which is already close to machine code to actual machine code?
I would go with the later any day and in the past for me ASP.NET always has been proven to be faster.
Yes. The absolute first time you access a page it might take longer, but this is not the case you should think about, its the 10th and 20th visitor that you should have in mind.
精彩评论