# JIT Compiling Code in 5μs

> Hacker News story 49406387 · language: en · submitted 2026-08-23
> Web version: https://zeli.app/story/49406387
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 162 · by [zX41ZdbW](<https://news.ycombinator.com/user?id=zX41ZdbW>) · 💬 104
[original](<https://malisper.me/jit-compiling-code-in-5-us/>) · [HN discussion](<https://news.ycombinator.com/item?id=49406387>)

## Summary

Historically, fast JIT compilation was a black art requiring deep assembly knowledge. Now, with AI assistance, it's easier than ever. The author built pgrust, a database with a JIT compiler that compiles SQL queries in about 5μs, enabling JIT compilation for every query. This post walks through building a simple regex engine with a JIT compiler using copy-and-patch stencils, targeting ARM64 assembly, and achieving performance comparable to handwritten code.

## Key quote

> To write a fast JIT compiler, you would need to know how to write assembly.

## HN discussion (104 comments)

### [MaxBarraclough](<https://news.ycombinator.com/item?id=49407068>)

> 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

### [agnishom](<https://news.ycombinator.com/item?id=49407735>)

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

### [catlifeonmars](<https://news.ycombinator.com/item?id=49409372>)

> This is perhaps a little meta, but this was a pleasant read. It’s refreshing to read an article about using an LLM that doesn’t read like it was also written by that LLM.
>
> I might use this approach to generate the stencils for a JIT firewall I’ve been experimenting with.
>
> It also occurs to me that this could be used to generate eBPF byte code on the fly as well

### [glum64](<https://news.ycombinator.com/item?id=49406947>)

> 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...).

### [mgaunard](<https://news.ycombinator.com/item?id=49407636>)

> 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.

### [malisper](<https://news.ycombinator.com/item?id=49409005>)

> Author here. Let me know if you have any questions about the post or about pgrust.

### [glenjamin](<https://news.ycombinator.com/item?id=49406837>)

> 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?

### [hamilyon2](<https://news.ycombinator.com/item?id=49407281>)

> It uses copy-and-patch compilation to archive that

---

## Cite

- Page: https://zeli.app/story/49406387
- Date: 2026-08-23
- Source: malisper.me (https://malisper.me/jit-compiling-code-in-5-us/)
- Hacker News: https://news.ycombinator.com/item?id=49406387

## Other languages

- zh: https://zeli.app/zh/story/49406387 · markdown: https://zeli.app/zh/story/49406387.md
- ja: https://zeli.app/ja/story/49406387 · markdown: https://zeli.app/ja/story/49406387.md
- ko: https://zeli.app/ko/story/49406387 · markdown: https://zeli.app/ko/story/49406387.md
- de: https://zeli.app/de/story/49406387 · markdown: https://zeli.app/de/story/49406387.md
- es: https://zeli.app/es/story/49406387 · markdown: https://zeli.app/es/story/49406387.md
- ru: https://zeli.app/ru/story/49406387 · markdown: https://zeli.app/ru/story/49406387.md
