How to JIT compile code in 5 microseconds

How to JIT compile code in 5 microseconds

Writing a custom JIT compiler used to mean wrestling with raw assembly or waiting on heavy toolchains like LLVM.

Developer Malisper showed how to bypass that overhead entirely using AI assistance and a technique called copy-and-patch. While building pgrust, they built a JIT compiler that turns code into executable machine instructions in around 5 microseconds.

Why it matters: Most databases skip JIT compilation for simple tasks because LLVM or C/C++ code generation takes too long to compile. A 5-microsecond compile budget changes the math: you can JIT compile every single query, matching handwritten code speeds (often 10–20× faster than basic interpreters) without taking a heavy latency hit upfront.

Think of copy-and-patch like fill-in-the-blank Mad Libs for assembly. The engine takes pre-built machine code templates called "stencils", fills in runtime specifics, stitches them together, and copies the result straight into executable memory.

Heavy compiler frameworks might finally lose their monopoly on fast runtime execution.

Sources