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

InterpreterComplier
Quick FeedbackDelayed Feedback
REPLCompiled Code
Byte CodeMachine Code
Easy to implement and understandDifficult to understand
SpeedEfficiency
Has less contextHas more context
Local optimisations onlyGlobal Optimisaitons
simple and quick to start but slow to executecomplex 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.

    All notes