{
  "id": 2748470,
  "title": "JIT Compiling Code in 5μs",
  "url": "https://urgent.news/2026/08/23/jit-compiling-code-in-5-s-2748470",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-23T07:44:50.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://malisper.me/jit-compiling-code-in-5-us/"
  },
  "original_language": "en",
  "account": "In the realm of programming, fast Just-In-Time (JIT) compilation has often been considered a complex endeavor, requiring expertise in assembly language. However, recent advancements in artificial intelligence have made it much simpler to create JIT compilers that compile code at runtime with remarkable speed. This breakthrough is particularly impactful for databases, which previously relied on slower compilation methods like LLVM or C/C++ code generation.\n\nOne noteworthy example of this advancement is the pgrust project, where the author initially doubted the feasibility of implementing a JIT compiler. Yet, with the help of AI, the process turned out to be far more straightforward than anticipated, contributing to the project's overall performance. The pgrust JIT compiler can compile code in just 5 microseconds, allowing it to JIT compile every SQL query, rather than just a fraction of them.\n\nJIT compilation is a technique that generates executable code at runtime, often resulting in significant performance improvements, typically ranging from 2 to 5 times faster, and sometimes even more. This technique is especially valuable when programming language interpreters encounter runtime information that significantly alters program behavior. JIT compilers are not limited to programming languages; they also play a crucial role in parsing data, especially when the schema is only known during runtime.\n\nTo illustrate the power of JIT compilation, the author created a toy regular expression engine that supports only literal strings and repetition (i.e., the regex *). This engine was implemented using Rust structures, enabling it to handle strings such as \"b(an)*\" without the need for alternation or lookbehind features.\n\nA straightforward interpreter for this regular expression engine was developed, consisting of under 20 lines of code. However, when benchmarked against a manually written version optimized for the regex, the interpreter proved to be 10-20 times slower. This stark contrast highlighted the potential for performance improvement through JIT compilation.\n\nTo leverage JIT compilation, two main steps are required. First, the assembly code for the desired runtime operations must be generated. This is achieved through a process called copy-and-patch. In this approach, predefined assembly templates, known as \"stencils,\" are customized based on the specifics of the operation being JIT compiled. By combining these customized stencils, a program can be constructed at runtime that achieves performance comparable to manually written code.\n\nThe author demonstrates this process by generating ARM64 assembly code for the regex \"b(an)*\". The code is broken down into distinct sections, starting with the prologue, which initializes the program's state by setting the stack pointers. Following the prologue, the code checks for the literal string \"b\" and handles any non-matching characters by jumping to a fallback logic block. Subsequently, the repetition section (an)* is addressed, which involves backtracking logic to handle potential failed matches.\n\nThe final section of the generated assembly code concludes the regex by checking if the end of the string has been reached. If so, the function returns 1 to indicate a successful match; otherwise, it signifies a failed match. This JIT-compiled regular expression engine demonstrates the immense potential for performance gains when employing JIT compilation techniques.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 2,
    "also_reported_by": [
      {
        "outlet": "Hacker News",
        "title": "JIT Compiling Code in 5μs",
        "url": "https://urgent.news/2026/08/23/jit-compiling-code-in-5-s",
        "published": "2026-08-23T06:04:51.000Z"
      }
    ]
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}