JIT Compiler: Tracing vs Function Mode
PHP 8.0 introduced the Just-In-Time (JIT) compiler — the most significant performance change since PHP 7. This page explains how JIT works, when it helps, and how to configure it.
What is JIT?
PHP normally executes through OPcache: source → opcodes (bytecode) → Zend Engine interpretation. JIT adds a third step: opcodes → native machine code, compiled at runtime.
Without JIT: PHP Source → OPcache Bytecode → Interpreter → CPU
With JIT: PHP Source → OPcache Bytecode → JIT → Native Code → CPU
JIT Modes
PHP's JIT has two compilation strategies:
| Mode | Config Value | Description |
|---|---|---|
| Tracing JIT | 1254 | Identifies "hot paths" via runtime profiling and compiles them |
| Function JIT | 1205 | Compiles entire functions ahead of execution |
Tracing JIT is the default and typically gives the best results for web workloads.
Configuration
In php.ini or conf.d/jit.ini:
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=256
opcache.jit_buffer_size=128M
opcache.jit=1254
The opcache.jit value is a 4-digit bitmask:
| Position | Controls |
|---|---|
| 1st digit (C) | CPU-specific optimizations (0=off, 1=on) |
| 2nd digit (R) | Register allocation (0=none, 5=full) |
| 3rd digit (O) | JIT optimization level (0-5) |
| 4th digit (T) | Trigger: 0=always, 1=tracing, 2=function, 3=on-request, 4=startup |
1254 = CPU optimizations on, full register allocation, max optimization, tracing trigger.
When JIT Helps (and When It Doesn't)
JIT provides the most benefit for CPU-bound workloads:
✅ Mathematical computations (image processing, machine learning inference) ✅ Long-running processes (CLI scripts, queue workers) ✅ Tight loops with heavy arithmetic
❌ Typical web request/response cycles (I/O-bound — JIT doesn't help with database queries or HTTP calls) ❌ Framework-heavy applications (Laravel, Symfony) — minimal improvement in benchmarks
Real-world verdict: For typical Laravel/Symfony CRUD apps, JIT provides 0-5% improvement. For CPU-intensive work (image manipulation, crypto, scientific computing), it can improve performance 20-50%.
Benchmarking JIT Impact
# Test without JIT
php -d opcache.jit=0 -d opcache.jit_buffer_size=0 benchmark.php
# Test with Tracing JIT
php -d opcache.jit=1254 -d opcache.jit_buffer_size=128M benchmark.php
JIT + Preloading (Production Combo)
For maximum performance, combine JIT with preloading:
opcache.preload=/var/www/html/preload.php
opcache.preload_user=www-data
opcache.jit=1254
opcache.jit_buffer_size=128M
JIT compiles frequently-executed preloaded code into native instructions that persist for the process lifetime.