5 ms·
There is no "shift away from JIT", just a simple observation that JITs are a tradeoff that you sometimes don't want to make. They have three drawbacks and two a
by pron 11y ago
There is no "shift away from JIT", just a simple observation that JITs are a tradeoff that you sometimes don't want to make. They have three drawbacks and two advantages. The three drawbacks are 1/ slow warmup, 2/ somewhat increased RAM and CPU usage and 3/ complex implementation. The two advantages are 1/ (often much) better runtime performance (i.e. more optimized code) and 2/ much better support for runtime manipulation of code (for profiling, debugging "at-full-speed", hot-patching, monitoring etc.).
The slow warmup makes JITs a bad choice for quick command-line tools, and the increased RAM/CPU makes them a bad choice for battery-powered devices and those with very limited RAM. The better performance and optimization opportunities makes them the only performant choice for some languages that are hard to optimize AOT (those that rely a lot on dynamic dispatch and/or have dynamic data-structures, i.e. maps instead of class instances). The better instrumentation support makes them a terrific choice for long-running server-side application, where the drawbacks don't matter. On the client-side, unless the language requires a JIT for decent performance (like JS), there is no compelling reason to use one, and that's why Microsoft's decision makes perfect sense, as they've decided to focus on .NET on the client. This has nothing to do with JITs' great utility in general.
One of the biggest breakthroughs in compiler technology in the last decade is Oracle Lab's Graal[1], which can also be used as an AOT, but with less-powerful optimizations. E.g. Graal does this: https://twitter.com/ChrisGSeaton/status/619885182104043520 https://twitter.com/ChrisGSeaton/status/619885182104043520
Graal (alongside its language-construction DSL, Truffle) has yielded implementations of Ruby, Python and JS that easily rival the state-of-the-art with far, far less effort, and also a very decent implementation of C (also with orders-of-magnitude less effort than the competition).
The third drawback makes developing JITs from scratch a bad choice for anyone but the most well-resourced teams, or those that are in no hurry, or those that target very simple languages only.
JITs have another drawback -- less predictable performance -- that matters mostly for hard-realtime code (or nearly hard-realtime), as deopts that momentarily slow-down performance as a better optimization strategy is sought. This is why hard-realtime JVMs offer a mixed JIT/AOT mode, where the hard realtime kernel (which values predictability over perfroamce) is AOT compiled, and the soft-realtime or non-realtime support code is JITted (which you want to run as fast as possible, but don't mind a rare hiccup).
[1]: https://wiki.openjdk.java.net/display/Graal/Publications+and+Presentations https://wiki.openjdk.java.net/display/Graal/Publications+and...
- bjourne 11y ago> 1/ (often much) better runtime performance (i.e. more optimized code) and Do you have a cite for that? Except for method inlining, which only requires a trivial JIT compiler, I haven't seen them beating normal compilers. The argument that you should be able to use the programs runtime data to perform specific optimizations seems to me to be oversold. Since the JIT compiler must be reasonably fast it eschews many optimization techniques that AOT compilers can afford to use.
- pron 11y agoLook at the tweet I linked to. And bear in mind that languages that are normally AOT-compiled (like C and C++) are often designed in such a way that information that is pertinent to most optimization is available at compile time, plus programmers in those languages don't make use of more general abstractions unless they have to (which makes, say, C++ more complicated as it has two dispatch mechanism that the user needs to be aware of). Such languages obviously won't be accelerated much by a JIT, but they have a big complexity cost, as various low-level optimization considerations have to be exposed by the language. JITs make simpler, higher-level languages as performant, and there's plenty of data to support that.
- bjourne 11y agoBut your claim was "(often much) better runtime performance" What you link to doesn't support that. I can concede that a JIT can attain equivalent performance to AOT compiled code. But I haven't seen any evidence that JIT:ing in practice increases performance. Note that there are many modern high-level performant languages that do not use a JIT, like Nim, Haskell, Julia and Rust. For example, the V8 engine has both a JIT an AOT compiler. The engine compiles all code with the fast AOT compiler and then recompiles frequently used functions with the optimizing JIT compiler. If it instead compiled all code with the optimizing compiler AOT, the JIT part wouldn't be needed and you would get just as fast code. JIT can only beat AOT if you can exploit patterns in the dataflow of the program. Doing that profitably (i.e. the optimization must save more time than it costs to perform) is incredibly hard.