JIT or precompilation?
- An acronym for "just-in-time," a phrase that describes an action
that is taken only when it becomes necessary, such as just-in-time
compilation or just-in-time object activation.
- JIT compilation
- The compilation that converts Microsoft intermediate language (MSIL)
into machine code at the point when the code is required at run time.
- Process of generating of native images on demand.
There are plenty of articles on the theme. I've decided I can express
my opinion on as I've studied JIT enough to see most of its
advantages and drawbacks. Please do not expect me to be fully objective,
since for me precompilation is just better. :-)
Criticism of JIT
- Permanent consumption of processor resources
- Every time assembly is loaded into a proccess, JIT is used to
compile methods into native code. Considering that JIT also often
performs verification during its compilations the whole process becomes
just a permanent repeating of operations that once were successfully
- Consumption of memory resources
- Methods being compiled by JIT reside in address space of
process, and are not subject of code sharing which is common case for
native code. The problem will become more tight in future when more
applications will use CLR and there will be more libraries to share.
- Time frame limitation
- JIT's only a service of application not an application itself, and
it have to do its job fast, and allow to application to perform its
functionality. As result JIT lacks optimization analysis layer, it
does not handle complex code patterns (it maps IL instruction to set of
native instructions, however using optimization analysis it's possible
to map set of IL instructions to set of native instructions more
- Compilation on as need basis
- JIT compiles methods on as need basis, on the other hand
precompilation performs its work in one go. It's obvious that
precompilation in one pass is faster than dispersed JIT compilation
of all methods of assembly as this allowing to accumulate resources to
perform work in more efficient way.
Advantages of precompilation
Copyright (c) 2003-2005 by Nesterovsky bros
- One time compilation
- User, in my opinion, is more tolerate to "cache time", "install
time" compilation (which is rare process), then to JIT compilation
(which is regular process).
- Caching native images
- Precompilation is allowing creation of caching service
which stores native images along with cache information about:
- expiration - to optimize disk usage by deleting or compressing
images that are not in use
- dependency - invalidation of images that depend on other
- satelites - caching dynamic assemblies, which in fact immutable
product of assembly such as generic template instantiations, or
dynamically generated classes for xml serialization and web services,
or regex compiled expressions, and so on.
- Precompilation can afford to perform deep optimizations, as it's not
limited with time in such a way as JIT is.
- Code sharing
- From the OS perspective precompiled assemblies are regular libraries
and participate in code sharing (OS shares loaded libraries
between processes) and page pumping (OS loads memory pages where library
is mapped on touch) policies.