Search code examples
javaccompiler-constructioncompilationprogramming-languages

Dynamically compiled language vs statically compiled language


The first line of this article by Brian Goetz made me to post this question in SO . Here 's the line again:

Writing and interpreting performance benchmarks for dynamically compiled languages, such as Java, is far more difficult than for statically compiled languages like C or C++.

I know the answer of statically typed vs dynamically typed language . But what is the difference between dynamically compiled language vs statically compiled language?


Solution

  • Dynamic compiled and dynamically typed don't have much to do with each other. Typing is part of the language syntax, while the compilation strategy is part of the implementation of the language.

    Dynamic typing means that you don't necessarily have to declare the type when you declare a variable and that conversion between types happens automatically in most cases.

    Dynamic compiling means that the language is compiled to machine code while the program is being executed, not before. This allows, for example, just-in-time optimization - the code is optimized while the application is running. A JIT optimizer has the advantage that it has much more reliable information about which branches of the code are used most often and how they are usually used, because it can observe the application in action before applying optimizations.

    Dynamic compilation is a problem for automatic benchmarking, because multiple measurements of the same program code section can compare completely different machine code interpretations because the optimizer has decided to change the implementation between two runs.