JIT Compiling Code in 5μs

(malisper.me)

52 points | by zX41ZdbW 3 hours ago

4 comments

  • MaxBarraclough 40 minutes ago
    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

  • glum64 1 hour ago
    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...).

  • glenjamin 1 hour ago
    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?
  • roschdal 1 hour ago
    JIT compilation is unsecure.
    • asdfsa32 30 minutes ago
      You're entirely correct because JIT requires violating Write xor Execute security policy. This is the reason on iOS, it is limited to Apple shipped software.

      https://en.wikipedia.org/wiki/W%5EX

      • shakna 23 minutes ago
        The wiki page mentions this is only a minor problem. Because everyone just writes, then switches and executes.
        • asdfsa32 3 minutes ago
          But this means that you have to decide who is allowed to switch.
    • sebzim4500 33 minutes ago
      Maybe, but surely there are users who are willing to trust all users of their db instance.
      • asdfsa32 29 minutes ago
        The issue is that it restricts from locking-down and securing the system with Write xor Execute memory. So it has system wide implication.

        https://en.wikipedia.org/wiki/W%5EX

        • PhilipRoman 16 minutes ago
          W^X is typically per mapping, not per memory page and does not interfere with JIT compilation.
    • dennis16384 1 hour ago
      It is the core of ClickHouse for example, for many years. Is it secure enough in your opinion?