What are the advantages of just-in-time compilation versus ahead-of-time compilation?

前端 未结 9 2310
挽巷
挽巷 2020-12-02 05:56

I\'ve been thinking about it lately, and it seems to me that most advantages given to JIT compilation should more or less be attributed to the intermediate

9条回答
  •  感动是毒
    2020-12-02 06:29

    The ngen tool page spilled the beans (or at least provided a good comparison of native images versus JIT-compiled images). Executables that are compiled ahead-of-time typically have the following benefits:

    1. Native images load faster because they don't have much startup activities, and require a static amount of fewer memory (the memory required by the JIT compiler);
    2. Native images can share library code, while JIT-compiled images cannot.

    Just-in-time compiled executables typically have the upper hand in these cases:

    1. Native images are larger than their bytecode counterpart;
    2. Native images must be regenerated whenever the original assembly or one of its dependencies is modified.

    The need to regenerate an image that is ahead-of-time compiled every time one of its components is a huge disadvantage for native images. On the other hand, the fact that JIT-compiled images can't share library code can cause a serious memory hit. The operating system can load any native library at one physical location and share the immutable parts of it with every process that wants to use it, leading to significant memory savings, especially with system frameworks that virtually every program uses. (I imagine that this is somewhat offset by the fact that JIT-compiled programs only compile what they actually use.)

    The general consideration of Microsoft on the matter is that large applications typically benefit from being compiled ahead-of-time, while small ones generally don't.

提交回复
热议问题