vladich/pg_jitter: Better JIT for Postgres · GitHub

vladich/pg_jitter: Better JIT for Postgres · GitHub

PostgreSQL JIT Compilation Just Got a Major Speed Boost with pg_jitter

PostgreSQL’s JIT (Just-In-Time) compilation, introduced in version 11 back in 2018, has been a game-changer for query performance on complex workloads. By compiling expressions and avoiding inefficient per-row loops during runtime, JIT significantly accelerates execution for expression-heavy queries and wide tables. However, the standard LLVM-based JIT compiler has been notoriously slow, with compilation times ranging from tens to hundreds of milliseconds—making it suitable only for very heavy OLAP-style queries.

Enter pg_jitter, a revolutionary lightweight JIT compilation provider that’s about to change everything for PostgreSQL users. This innovative extension adds three alternative JIT backends—SLJIT, AsmJit, and MIR—delivering microsecond-level compilation times instead of the sluggish milliseconds we’ve grown accustomed to with LLVM.

The Performance Revolution

Let’s talk numbers. While LLVM typically takes tens to hundreds of milliseconds to compile, pg_jitter’s backends operate at dramatically faster speeds:

  • SLJIT: Tens to low hundreds of microseconds
  • AsmJit: Hundreds of microseconds
  • MIR: Hundreds of microseconds to single milliseconds

That’s up to 1000x faster compilation! But speed isn’t the only advantage. pg_jitter makes JIT worthwhile for a much wider range of queries, including typical OLTP workloads where LLVM’s overhead would previously exceed the query execution time itself.

Backend Breakdown: Choose Your Weapon

Each backend in pg_jitter brings unique strengths to the table:

SLJIT is the undisputed champion of consistency, delivering 5-25% faster performance than the interpreter across all workloads. Its phenomenal compilation speed makes it the best choice for most scenarios, especially when you need reliable, predictable performance.

AsmJit shines when dealing with wide-row, deform-heavy queries, offering up to 32% faster execution thanks to its specialized tuple deforming capabilities. If your workloads involve complex data structures, AsmJit is your go-to solution.

MIR provides solid performance gains while being the most portable backend, supporting a wide range of architectures. It’s the perfect choice when you need flexibility across different deployment environments.

Real-World Impact

The benchmarks speak for themselves. On ARM64 (Apple Silicon M1 Pro) and x86_64 (Ryzen AI 9 HX PRO 370) platforms, pg_jitter consistently outperforms the standard LLVM backend. In fact, LLVM’s performance on super wide table queries is simply atrocious—sometimes 10x to 30x slower than the baseline!

What makes this even more impressive is that pg_jitter achieves these gains while maintaining compatibility with PostgreSQL versions 14 through 18 from a single codebase. The extension implements PostgreSQL’s JitProviderCallbacks interface, walking expression evaluation opcodes and emitting native machine code for approximately 30 hot-path operations.

Zero-Configuration, Maximum Flexibility

One of pg_jitter’s most appealing features is its zero-config approach. Simply set the jit_provider parameter and you’re off to the races. The extension also supports runtime backend switching via SET pg_jitter.backend = 'sljit' without requiring a server restart—giving you unprecedented flexibility to optimize for different workloads on the fly.

The meta provider (jit_provider="pg_jitter") acts as a smart dispatcher, exposing a pg_jitter.backend GUC that’s user-settable and supports lazy loading of backend shared libraries. If your preferred backend isn’t installed, it automatically falls back to the next available option.

Advanced Features for Power Users

For those seeking maximum performance, pg_jitter offers two-tier function optimization. Tier 1 handles pass-by-value operations (integers, floats, booleans, dates, timestamps, OIDs) as direct native calls with inline overflow checking—eliminating FunctionCallInfo overhead entirely. Tier 2 manages pass-by-reference operations through DirectFunctionCall C wrappers, with optional LLVM or c2mir optimization.

The extension also supports precompiled function blobs, allowing you to extract native code for hot functions at build time and embed them directly into the shared library. This optional feature requires either the LLVM pipeline (using clang and llvm-objdump) or the c2mir pipeline (no extra dependencies needed).

Installation and Usage

Getting started with pg_jitter is straightforward:

bash

Build all backends

./build.sh

Install and restart PostgreSQL

./install.sh

Use a specific backend

ALTER SYSTEM SET jit_provider = ‘pg_jitter_sljit’;
SELECT pg_reload_conf();

Or use meta provider for runtime switching

ALTER SYSTEM SET jit_provider = ‘pg_jitter’;
SELECT pg_reload_conf();
SET pg_jitter.backend = ‘asmjit’; — switch on the fly

The Bottom Line

pg_jitter represents a quantum leap forward in PostgreSQL JIT compilation technology. By offering microsecond-level compilation times, multiple specialized backends, and unprecedented flexibility, it makes JIT optimization accessible and beneficial for virtually any PostgreSQL workload.

Whether you’re running complex analytical queries, high-throughput OLTP systems, or anything in between, pg_jitter delivers the performance improvements you need without the complexity you don’t want. The extension is currently in beta quality, having passed all standard PostgreSQL regression tests and showing impressive improvements in performance benchmarks.

For PostgreSQL users looking to squeeze every last drop of performance from their databases, pg_jitter isn’t just an option—it’s becoming a necessity. The future of PostgreSQL performance is here, and it’s called pg_jitter.


Tags: PostgreSQL, JIT compilation, database performance, SLJIT, AsmJit, MIR, query optimization, OLTP, OLAP, database acceleration, microsecond compilation, pg_jitter

Viral Phrases: “1000x faster compilation times”, “game-changer for PostgreSQL performance”, “microsecond-level compilation”, “revolutionizing database optimization”, “the future of PostgreSQL performance”, “unprecedented flexibility in JIT compilation”, “zero-configuration performance boost”, “choose your weapon: three specialized backends”, “10x to 30x performance improvement”, “making JIT worthwhile for any workload”

,

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *