logoalt Hacker News

JIT Compiling Code in 5μs

101 pointsby zX41ZdbWtoday at 6:04 AM54 commentsview on HN

Comments

MaxBarracloughtoday at 8:32 AM

Reminds me of the 2024 blog post Look ma, I wrote a new JIT compiler for PostgreSQL [0]. Both articles lament that Postgres's LLVM-based JIT [1] takes a while to generate code.

> The rarity of JIT compilers makes me believe that implementing a JIT compiler historically was too difficult for it to be worthwhile.

That's only true of writing a JIT from scratch. There's no rarity of JITs, it's just that LLVM (and other frameworks) are often used. Every major interpreter has a JIT compiler. PCRE2 has a JIT compiler. There are JIT frameworks out there with much faster code-generation than LLVM: Cranelift, GNU Lightning, Mir. I doubt they could do code-generation faster than a custom copy-and-patch JIT, but they'd be much faster than LLVM.

[0] https://www.pinaraf.info/2024/03/look-ma-i-wrote-a-new-jit-c... , discussed: https://news.ycombinator.com/item?id=39742916

[1] https://www.postgresql.org/docs/current/jit-reason.html

show 2 replies
agnishomtoday at 10:45 AM

I recommend Russ Cox's articles on implementing a regex engine: https://swtch.com/~rsc/regexp/

It is very relevant

mgaunardtoday at 10:25 AM

The problem with the approach is that it's not real JIT-compilation, it's just assembly templates with basic substitutions.

By not using LLVM, you're missing all the optimizations it does.

show 3 replies
glum64today at 8:06 AM

Uhm, Common Lisp, where JIT is not only available but is also manageable: the programmer can decide what deserves to be compiled and what does not.

Besides run time, JIT is available also when the code is compiled or loaded for execution (i.e., do you have a compilation or loading speed-up in mind? no problem, you can also compile that speed-up into native machine code, and so ad infinitum...).

show 2 replies
hamilyon2today at 9:21 AM

It uses copy-and-patch compilation to archive that

glenjamintoday at 7:45 AM

pgrust sounds very interesting, but with the deep changes there’s no viable path to upstream it - is the end goal to be robust enough that it’ll get wide adoption?

show 1 reply
Gamer_S4lyertoday at 11:32 AM

Nice

ligarotatoday at 11:05 AM

Tcc be like

varjagtoday at 9:31 AM

There’s been a meme circulating about how AI doesn’t help because “code was never the hard part.” I think that’s true in some domains, but in others, writing the code absolutely was the hard part. JIT compilers are a great example of that.

show 1 reply
uygartoday at 12:12 PM

[dead]

roschdaltoday at 7:46 AM

JIT compilation is unsecure.

show 7 replies