ES012: JIT overhead dominates
- Signal: JIT compilation takes at least half of the execution time.
- Evidence: functions compiled, the time of each compilation step, and the execution time.
- Action: raise
jit_above_cost, or setjit = offfor OLTP workloads. When inlining and optimization dominate, raisingjit_inline_above_costandjit_optimize_above_costkeeps JIT but drops its most expensive steps.
Example
The jit_overhead scenario of the test corpus, captured on PostgreSQL 16: JIT compilation forced on a tiny query, so compiling takes far longer than executing.
SELECT count(*), sum(amount) FROM orders WHERE id <= 100;
Aggregate (cost=11.54..11.55 rows=1 width=40) (actual time=99.751..99.753 rows=1 loops=1)
Output: count(*), sum(amount)
Buffers: shared hit=5
-> Index Scan using orders_pkey on public.orders (cost=0.42..11.06 rows=94 width=6) (actual time=0.035..0.068 rows=100 loops=1)
Output: id, customer_id, status, created_at, amount, note
Index Cond: (orders.id <= 100)
Buffers: shared hit=5
Settings: jit_above_cost = '0', jit_inline_above_cost = '0', jit_optimize_above_cost = '0', max_parallel_workers_per_gather = '0'
Planning:
Buffers: shared hit=103
Planning Time: 0.533 ms
JIT:
Functions: 5
Options: Inlining true, Optimization true, Expressions true, Deforming true
Timing: Generation 0.334 ms, Inlining 65.541 ms, Optimization 19.775 ms, Emission 14.332 ms, Total 99.982 ms
Execution Time: 117.904 ms
explainsql reports:
HIGH ES012 JIT overhead dominates
JIT compilation took 100.0 ms of the 117.9 ms execution (85%).
Functions compiled: 5
Compilation: generation 0.334 ms, inlining 65.5 ms, optimization 19.8 ms, emission 14.3 ms
Execution time: 117.9 ms
→ Raise jit_above_cost so that JIT only starts for queries that run long enough to benefit, or set jit = off for OLTP workloads. Most of the time went to inlining and optimization: raising jit_inline_above_cost and jit_optimize_above_cost keeps JIT but drops its most expensive steps.