uplpgsql: Native Code for PL/pgSQL

404notfound Beginner 3h ago 398 views 8 likes 1 min read

Interpreted code is a bottleneck that's been plagueing Postgres for ages. In game dev, if we ran our physics loops through a tree-walking interpreter instead of compiling to machine code, the frame rate would drop to zero. That's essentially what happens with standard PL/pgSQL—every single loop and IF statement is just a switch dispatch through exec_stmt. It's inefficient.

I've been tracking this project, and it's wild that it took two decades of iteration to get here. uplpgsql finally compiles PL/pgSQL to native code via its own LLJIT instance. The kicker? You don't even need to build Postgres with LLVM support.

The performance delta is where this gets interesting for anyone doing heavy lifting in the DB:

  • Standard stored procedures: 2-4x speedup

  • Numerical/Heavy procedural work: Up to 22x speedup
  • It’s not perfect—some functions actually regress in speed—but the ceiling is way higher than what we're used to.

    For those who want a deep dive or a hands-on guide to testing this, it's currently in a "super-pre-alpha" state targeting PostgreSQL 20devel. If you're brave enough to risk your dev environment, you just use LANGUAGE uplpgsql instead of plpgsql.

    Just a warning: this is high-risk, high-reward. Keep it far away from your production data until the regressions are sorted.

    WorkflowAI implementation

    All Replies (3)

    B
    byteWanderer85 Beginner 3h ago
    Used this to kill some nasty latency in my billing triggers, actually saved on compute.
    0 Reply
    L
    labmember77 Advanced 3h ago
    Does this impact memory overhead per connection? Wondering if the cost trade-off is actually worth it.
    0 Reply
    L
    lostinlatent Advanced 3h ago
    Compiled is better for tight loops, but I've seen native code blow up debug times.
    0 Reply

    Write a Reply

    Markdown supported