Live data from Hacker News

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

pinaraf.info

31–40 of 66 posts

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

#31
post #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.

When you say it's "hard" to obtain--is it possible to obtain if you aren't Apple? Does Apple ever provide it to third party developers, or is there even a path to requesting it?

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

#32
post #30

Earlier quoted context omitted.

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.

To re-optimize compiled code blocks isn't without effort. Google has publicly spoken about AutoFDO and Propeller [0], after Meta had open sourced BOLT [1] in 2021.

AutoFDO has since been ported to Android and adopted by Yandex [3].

[0] https://lwn.net/Articles/995397/

[1] https://news.ycombinator.com/item?id=40868224

[2] https://news.ycombinator.com/item?id=42896716

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

#33
post #9

> This is called branch prediction, it has been the source of many fun security issues... No, that's speculative execution you just described. Branch prediction was implemented long before out-of-order CPUs were a thing, as you need branch prediction to make the most of pipelining (eg. fetching and decoding a new instruction while you're still executing the previous one--if you predict branches, you're more likely to…

Speculative execution does not require out-of-order execution. When you predict a branch, you're speculatively executing the predicted branch. Whether you're doing it in the same order as instruction order or out of order is independent of that.

If you're executing instructions in order, wouldn't you already know the result of the branch by the time you reach its code?

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

#34
post #30

Earlier quoted context omitted.

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.

Especially after PGO (profiling guided optimization) gets most of the way there

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

#35

Earlier quoted context omitted.

Speculative execution does not require out-of-order execution. When you predict a branch, you're speculatively executing the predicted branch. Whether you're doing it in the same order as instruction order or out of order is independent of that.

If you're executing instructions in order, wouldn't you already know the result of the branch by the time you reach its code?

You're starting them in order and you're ending (retiring) them in order, but you're not necessarily ending one instruction before you're starting the next one. For instance, in a very simple pipeline, you can start decoding the next instruction before you've completed the previous one, so you can do some work in parallel.

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

#36
post #22

Earlier quoted context omitted.

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.

When you say it's "hard" to obtain--is it possible to obtain if you aren't Apple? Does Apple ever provide it to third party developers, or is there even a path to requesting it?

Yes.

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

#38

I'm not really interested in building an interpreter, but the part about scalar out of order execution got me thinking. The opcode sequencing logic of an interpreter is inherently serial and an obvious bottleneck (step++; goto step->label; requires an add, then a fetch and then a jump, pretty ugly). Why not do the same thing the CPU does and fetch N jump addresses at once? Now the overhead is gone and you just need t…

Depending on the bytecode, instructions might be variable-length, which means that you need to execute a nontrivial amount of logic to fetch more than just the next bytecode or handler. That said, I tinkered with adding a prefetch to Wizard's interpreter which basically moves the load of the next handler from the dispatch at the end to the first thing in the handler, and saw something like a 5% improvement.

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

#39
post #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.

[dead]

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

#40
post #36

Earlier quoted context omitted.

When you say it's "hard" to obtain--is it possible to obtain if you aren't Apple? Does Apple ever provide it to third party developers, or is there even a path to requesting it?

Yes.

Source? Is there any non-Apple app that has this entitlement?
Post reply on HN