Tech News
← Back to articles

Exploring Speculative JIT Compilation for Emacs Lisp with Java

read original related products more articles

If we analyze the code produced by Emacs, as is shown by the gray graph on the left, we can see that it has two paths: one fast path that does fast fixnum addition, and one slow path that calls out to an external plus-one function to handle floating numbers and big integers.

Figure 5: Comparison between AOT compilation and speculative JIT compilation

Now, if we pass integers into this function, it’s pretty fast because it’s on the fast path. However, if we pass in a floating number, it has to go through the slow path, doing an extra function call, which is slow.

What speculation might help here is that, it can have flexible fast paths. When we pass a floating number into this function, which currently has only fixnums on the fast path, it also has to go through the slow path (green graph in the middle). But the difference is that a speculative runtime can deoptimize and recompile the code to adapt to this. When it recompiles, it might look at the statistics and decide to add floating numbers to the fast path, and now floating number operations are also fast (green graph on the right). This kind of speculation is why speculative runtimes can be really fast.

nativecomp ( AOT ) Speculation-based JIT Fast path Fast 🚀 ~on par Slow path Slow Fast 🚀 (only after slow 🐌 recompilation)