12

I was studying the inner workings of V8 and came across the term JIT compiler. Initially, I read in this article https://www.quora.com/How-does-the-JIT-compiler-work-in-JS that JIT compiler in V8 is called "Ignition" which is interpreter. Then, I came to conclusion that JIT compiler is just interpreter. But later I found another article https://blog.logrocket.com/how-javascript-works-optimizing-the-v8-compiler-for-efficiency/ describing jit-compilation as the combination of both interpreter and compiler. Guys, is JIT compiler a really a combination of interpreter and compiler? or Is JIT compiler is just interpreter only?

Mita
  • 187
  • 1
  • 4
  • Just In Time ____? (fill in the blank; trivially one of the hypothesis in the final question can be ruled out) – user2864740 Jan 19 '20 at 07:19
  • The JIT “compiler” that emits machine code is TurboFan; Ignition represents internal bytecode, and although there is compilation from the AST to this bytecode such is not really considered JIT as it does not direct target machine hardware. (Compare to say, Java which requires an explicit compilation step to bytecode, which is JIT’ted during execution.) – user2864740 Jan 19 '20 at 07:21
  • @user2864740, thanks for your kind comments, so you mean jit compiler is not really a combination of interpreter and compiler but compiler itself that optimizes our code. Is that right? if so, why is it called just in time then? – Mita Jan 19 '20 at 07:31
  • 1
    @Mita because it optimises on the fly while the code is being executed, as opposed to before the application is run like Ahead of Time (AOT) compilers. You can see AOT in C, for example where you *first* compile the application and *then* run it. JIT essentially does the opposite. – VLAZ Jan 19 '20 at 07:50

2 Answers2

37

V8 developer here. Just to clarify and expand what commenters have been pointing out already:

  • "JIT" means "just in time", and means that some execution environment dynamically (i.e. at runtime) decides to produce something (typically machine code -- colloquially, "JIT" tends to mean "just-in-time compilation", although if you decide to prepare a meal exactly when you're hungry and then eat it right away when it's done, then that's technically also "JIT" preparation.) The canonical opposite would be a language like C/C++, which is compiled by the developer, long before being delivered to and executed by the user. Another "opposite" in a different direction is an execution environment that executes something without producing machine code dynamically. Such environments are typically called "interpreters".

  • In the past, V8 used to always produce machine code. It simply had no way to execute JavaScript that did not involve compiling it to machine code first. Obviously this happened on the client, so it was a textbook example of a just-in-time compiler (or, more accurately, a set of several compilers... oh well, details!).

  • In recent years, V8 has had an interpreter as its first execution tier. Now usage of terms gets complicated, because this interpreter "compiles" JavaScript "just in time" to bytecode (which is then interpreted), but when someone says "JIT compiler", they usually mean that it's not an interpreter.

  • V8 also has an optimizing compiler that produces machine code. It runs at runtime (when a function is considered hot), so it's a just-in-time compiler.

jmrk
  • 34,271
  • 7
  • 59
  • 74
  • that's interesting, I assumed the interpreter was built first and had compilation fitted into it for performance reasons later on. Why was an interpreter added later? Are there environments where node is ONLY able to interpret? – jfo Jan 24 '22 at 12:22
  • The primary reason for developing an interpreter was that it saves quite a bit of memory, because its bytecode is much smaller than machine code. This matters primarily on mobile devices. Being able to support environments that don't allow any JIT compilation is a secondary benefit, see https://v8.dev/blog/jitless. – jmrk Jan 24 '22 at 12:53
  • Thanks, will read the link. And of course I had meant to specify v8 rather than node specifically :) – jfo Jan 25 '22 at 13:20
  • Is jitless what causes serverfarms? – Nick Carducci for Carface Bank Jun 30 '22 at 23:11
-2

Transpile is to compost and "pile on to an ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT target."

target triple = "x86_64-apple-macosx10.7.0"
-march=x -mcpu=y, and -mattr=a,-b,+c.
ExecutionEnvironment/TargetSelect/selectTarget()

Can ...[one compile and execute with a triple target]?

For this reason, I would call v8 an interpreter/compiler, yet not sufficiently an interpreter yet for allegedly & sufficiently targeting the cloudflare service worker with rust-llvm wraps, alone - after all & to boot an interpreter is for application programming or graphical user interfaces (not a service worker for a v8 'edge' server). I believe the abstract syntax tree, target, and scope that global receiver mirrors all to be diametrically synonymous thus far in[ my] research.