by Stratoscope · 5y ago · 0 comments
They both work in exactly the same way. Your source code is compiled to bytecode. That bytecode is then interpreted by a virtual machine. [1] That interpreter may then start a Just In Time compiler (JIT) to compile some of the bytecode down to machine code.
Other than implementation details, both languages work the same way.
Python also works like this, except it does not have the JIT. But it also has a compiler which generates bytecode.
And even if a JIT generates what we fondly call "machine code", that code is interpreted too! What the CPU executes internally looks nothing like the machine code that we see as programmers.
It's interpreters all the way down.
[1] I don't mean in the sense of something like VMware; I'm talking about a software virtual machine that executes an instruction set which we call bytecode.
It's not just about compile-to-byte-code. It's about the "scriptyness" of that bytecode as well. Python bytecode operates at a much higher level of abstraction than machine code or even JVM.
Also we tend to classify languages with more dynamic type systems as "interpreted". It's a nebulous boundary. Not black-and-white whatsoever.
It just so happens that the “machine” is an abstraction of a CPU.
Interpreted Javascript doesn’t fit this bill. If compiled to web assembly then it would.
> As we turn to improving the performance of the actual initial JavaScript execution, however, we start to hit limitations when optimising our interpreter. V8’s interpreter is highly optimised and very fast, but interpreters have inherent overheads that we can’t get rid of; things like bytecode decoding overheads or dispatch overheads that are an intrinsic part of an interpreter’s functionality.
So when developers talk about a “compiled language” they really mean if the standard tooling supports a compiler; and if programs are generally distributed already-compiled.
There are implications (good and bad) to programs that are already compiled, versus a just-in-time compilation via a runtime engine; which is largely transparent to developers and end-users.