pg_jitter: Faster JIT for PostgreSQL

PostgreSQL's JIT compilation was introduced in version 11 to accelerate expression-heavy queries and tuple deforming. The problem? The default LLVM-based JIT takes tens to hundreds of milliseconds to compile. For OLTP workloads, that overhead often exceeds the query execution time itself. pg_jitter solves this with three lightweight JIT backends that compile in microseconds.
What is pg_jitter?
pg_jitter is a JIT compilation provider for PostgreSQL 14-18 that replaces LLVM with faster alternatives. It offers three independent backends:
- sljit: Fastest compilation (10s to 100s of microseconds), 5-25% faster than interpreter
- AsmJit: Best for wide-row queries, up to 32% faster on deform-heavy workloads
- MIR: Most portable backend with solid performance gains
The key advantage is compilation speed. Where LLVM takes 50-200ms (sometimes seconds), pg_jitter backends compile in microseconds, making JIT practical for a much wider range of queries.
Key Features
- Zero-config setup: Set
jit_providerand go - Runtime backend switching: Change backends via
SET pg_jitter.backendwithout restart - No LLVM dependency: Pure C/C++ with small, embeddable libraries
- PostgreSQL 14-18 support: One codebase covers all recent versions
- Two-tier optimization: Hot-path functions compiled as direct native calls
Installation
Clone the repository alongside the backend libraries:
git clone https://github.com/vladich/pg_jitter.git
git clone https://github.com/zherczeg/sljit.git
git clone https://github.com/asmjit/asmjit.git
git clone https://github.com/vladich/mir-patched.git mir
cd pg_jitter
./build.sh all
./install.sh
Configuration
Enable pg_jitter in PostgreSQL:
ALTER SYSTEM SET jit_provider = 'pg_jitter_sljit';
SELECT pg_reload_conf();
For runtime switching between backends:
ALTER SYSTEM SET jit_provider = 'pg_jitter';
SELECT pg_reload_conf();
SET pg_jitter.backend = 'asmjit';
Lower the JIT threshold for faster queries (default 100,000 is too high for pg_jitter):
SET jit_above_cost = 500;
Operational Tips
- Use sljit for general OLTP workloads with minimal overhead
- Use AsmJit for analytics queries on wide tables (many columns)
- Set
jit_above_costbetween 200-2000 depending on your workload - Avoid JIT for point lookups or single-row queries even with pg_jitter
Conclusion
pg_jitter makes PostgreSQL JIT compilation practical for everyday queries. By reducing compilation time from milliseconds to microseconds, it unlocks performance gains that were previously reserved for heavy OLAP workloads. For SRE teams running high-throughput PostgreSQL, this is a significant optimization opportunity.
If you're building an AI-powered platform for SRE teams, check out Akmatori, an open-source AI agent platform designed for infrastructure operations. For reliable cloud infrastructure, explore Gcore's global network.
