{
    "slug": "php_jit",
    "term": "PHP JIT — When It Helps (and When It Doesn't)",
    "category": "performance",
    "difficulty": "advanced",
    "short": "PHP 8.0's JIT compiler converts hot bytecode to native machine code — significant for CPU-bound code, but minimal for typical I/O-bound web requests.",
    "long": "PHP 8.0 introduced a JIT compiler (tracing and function modes) as an opcache tier. JIT compiles frequently-executed bytecode to native machine code, eliminating Zend VM interpreter overhead. Benchmarks show 2–4x speedups for pure CPU-bound PHP (number crunching, image processing, ML inference). For typical web applications dominated by database and HTTP I/O, JIT provides little measurable improvement — the CPU is rarely the bottleneck. Enable with opcache.jit=tracing and opcache.jit_buffer_size=128M. Profile first to confirm CPU is actually the bottleneck before expecting JIT to help.",
    "aliases": [
        "PHP JIT",
        "opcache.jit",
        "PHP Just-In-Time"
    ],
    "tags": [
        "php8",
        "php",
        "performance",
        "opcache"
    ],
    "misconception": "Enabling JIT always speeds up PHP applications. JIT benefits CPU-bound code like numeric computation. Typical web applications are I/O-bound — time is spent waiting on databases and external services, not executing PHP opcodes. JIT provides negligible or negative gains for most web apps.",
    "why_it_matters": "PHP 8's JIT compiles frequently executed code paths to native machine code — for CPU-bound workloads it can provide 2-3× speedups, though typical web I/O-bound applications see minimal improvement.",
    "common_mistakes": [
        "Enabling JIT and expecting web application speedups — most PHP web apps are I/O bound; JIT helps CPU-bound code.",
        "Not enabling OPcache first — JIT requires OPcache and builds on top of it.",
        "Using JIT mode 1255 without benchmarking — different modes (tracing vs function) suit different workloads.",
        "Not setting opcache.jit_buffer_size — JIT silently does nothing without a buffer allocated."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "opcache",
        "php_preloading",
        "profiling",
        "jit_compiler"
    ],
    "prerequisites": [
        "php_compilation_pipeline",
        "opcache",
        "bytecode_vm"
    ],
    "refs": [
        "https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.jit"
    ],
    "bad_code": "; php.ini — JIT not configured:\nopcache.enable=1\n; opcache.jit=1255         ; Missing — JIT disabled\n; opcache.jit_buffer_size= ; Missing — required\n\n; Correct for CPU-bound workloads:\nopcache.jit=1255\nopcache.jit_buffer_size=128M",
    "good_code": "; php.ini — enable JIT (PHP 8.0+)\n; JIT only helps CPU-bound code — not typical web I/O workloads\nopcache.enable=1\nopcache.jit_buffer_size=128M\nopcache.jit=tracing    ; best for most workloads\n; options: disable=0, minimal=1205, function=1205, tracing=1254\n\n; Verify JIT is active:\n; php -r 'var_dump(opcache_get_status()[\"jit\"]);'\n\n; Good for: image processing, data transformation, scientific computing\n; Neutral for: typical Laravel/Symfony request-response (I/O bound)\n; Benchmark your specific workload before relying on JIT gains",
    "quick_fix": "Enable JIT with opcache.jit=tracing and opcache.jit_buffer_size=128M — measure before and after; JIT helps CPU-bound code (image processing, crypto) but rarely helps I/O-bound web requests",
    "severity": "info",
    "effort": "low",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/php_jit",
        "html_url": "https://codeclaritylab.com/glossary/php_jit",
        "json_url": "https://codeclaritylab.com/glossary/php_jit.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[PHP JIT — When It Helps (and When It Doesn't)](https://codeclaritylab.com/glossary/php_jit) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/php_jit"
            }
        }
    }
}