Interpreter is line by line. So doesn't have the full context. Naturally any optimisation is not possible.
Compiler works with the whole code at once and hence it can come up with the optimised version of the code in the compiled code.
Interpreter - Speed, Compiler - Efficiency
Interpreter | Complier |
---|---|
Quick Feedback | Delayed Feedback |
REPL | Compiled Code |
Byte Code | Machine Code |
Easy to implement and understand | Difficult to understand |
Speed | Efficiency |
Has less context | Has more context |
Local optimisations only | Global Optimisaitons |
simple and quick to start but slow to execute | complex slow to start but fast to execute |
Just in time compilation
Start interpreting along with profiler. The hot code segments are sent to compiler for optimisation and uses the optimised code wherever possible.