Live data from Hacker News

JIT: So you want to be faster than an interpreter on modern CPUs

pinaraf.info

21–30 of 66 posts

Re: JIT: So you want to be faster than an interpreter on modern CPUs

#21
post #6
post #3

Good read. But a word of caution - the "JIT vs interpreter" comparisons often favor the interpreter when the JIT is inplemented as more-or-less simple inlining of the interpreter code. (Here called "copy-and-patch" but a decades-only approach). I've had fairly senior engineers try to convince me that this is true even for Java VMs. It's not in general, at least not with the right kind of JIT compiler design.

Yeah, I expect the real advantage of a JIT is that you can perform proper register allocation and avoid a lot of stack and/or virtual register manipulation. I wrote a toy copy-patch JIT before and I don't remember being impressed with the performance, even compared to a naive dispatch loop, even on my ~11 year old processor.

The difference between interpreters and simple JITs has narrowed partly due to two factors: better indirect branch predictors with global history, and wider execution bandwidth to absorb the additional dispatch instructions. Intel CPUs starting with Haswell, for instance, show less branch misprediction impact due to better ability to predict jump path patterns through the interpreter. A basic jump table no longer suffers as much compared to tail-calling/dispatch or a simple splicing JIT.

Re: JIT: So you want to be faster than an interpreter on modern CPUs

#22
post #4

A shame operating systems like iOS/iPadOS do not allow JIT. iPad Pro's have such fast CPU's that you cant even use fully because of decisions like this.

They do, technically, allow JIT. You need a very hard-to-obtain entitlement that lets you turn writable pages into executable read-only pages, and good luck getting that entitlement if (for some reason) your name isn’t “mobilesafari”, but the capability exists.

Re: JIT: So you want to be faster than an interpreter on modern CPUs

#24
post #23

The issues with branch prediction aren't really as much of a thing in modern interpreters, I can really recommend reading https://inria.hal.science/hal-01100647/document

The paper is 10 years old. While the gap between a threaded an interpreter (a dispatch at the end of every handler) versus non-threaded (loop over switch) isn't as big as it used to be, it's still 15-30% on modern very fast interpreters. For example, I measured between 14 and 29% performance improvement for threading Wizard's interpreter[1].

[1] https://dl.acm.org/doi/10.1145/3563311

Re: JIT: So you want to be faster than an interpreter on modern CPUs

#25
post #10
post #4

A shame operating systems like iOS/iPadOS do not allow JIT. iPad Pro's have such fast CPU's that you cant even use fully because of decisions like this.

What advantage does JIT compilation have over Swift or Obj-C?

JIT compilation can be faster for compiled languages too, as it allows data driven inlining and devirtualization, as well as "effective constant" propogation and runtime architecture feature detection

Re: JIT: So you want to be faster than an interpreter on modern CPUs

#26
post #4

A shame operating systems like iOS/iPadOS do not allow JIT. iPad Pro's have such fast CPU's that you cant even use fully because of decisions like this.

> that you cant even use fully because of decisions like this. Have no clue what this means - you can pre-compile for target platforms and therefore "fully" use whichever Apple device CPU.

[deleted]

Re: JIT: So you want to be faster than an interpreter on modern CPUs

#27
post #4

A shame operating systems like iOS/iPadOS do not allow JIT. iPad Pro's have such fast CPU's that you cant even use fully because of decisions like this.

> that you cant even use fully because of decisions like this. Have no clue what this means - you can pre-compile for target platforms and therefore "fully" use whichever Apple device CPU.

You can't precompile your web page's Javascript for iOS, even if you're willing to have it signed and notarized and submitted for policy review.

Re: JIT: So you want to be faster than an interpreter on modern CPUs

#28
post #4

A shame operating systems like iOS/iPadOS do not allow JIT. iPad Pro's have such fast CPU's that you cant even use fully because of decisions like this.

They allow, but Apple's policy is to lock down that ability pretty much just to Safari/WKWebView. If you could transpile/compile your program to JS or WASM and run it through one of these blessed options, it should get JIT'ted.

Re: JIT: So you want to be faster than an interpreter on modern CPUs

#29
post #27

Earlier quoted context omitted.

> that you cant even use fully because of decisions like this. Have no clue what this means - you can pre-compile for target platforms and therefore "fully" use whichever Apple device CPU.

You can't precompile your web page's Javascript for iOS, even if you're willing to have it signed and notarized and submitted for policy review.

Apart from the fact that its JS engine is really fast, Safari accepts WebAssembly. What else would you precompile it to?

Re: JIT: So you want to be faster than an interpreter on modern CPUs

#30
post #10

Earlier quoted context omitted.

What advantage does JIT compilation have over Swift or Obj-C?

JIT compilation can be faster for compiled languages too, as it allows data driven inlining and devirtualization, as well as "effective constant" propogation and runtime architecture feature detection

It can be but it never is.
Post reply on HN