{
    "slug": "jit_compilation_deep",
    "term": "JIT Compilation",
    "category": "compiler",
    "difficulty": "advanced",
    "short": "Just-in-Time compilation converts hot bytecode paths to native machine code at runtime — trading startup time for faster execution of frequently run code.",
    "long": "JIT compilers profile running code to identify hot paths (frequently executed), then compile those paths to native machine code. Two strategies: method JIT (compile entire methods) and tracing JIT (compile frequently executed traces across method boundaries). PHP 8's JIT uses a tracing approach. JIT benefits CPU-bound code (math, algorithms, image processing); I/O-bound PHP web apps see minimal improvement because they spend most time waiting for database/network, not executing CPU instructions.",
    "aliases": [
        "JIT",
        "just-in-time",
        "native compilation",
        "tracing JIT"
    ],
    "tags": [
        "compiler",
        "performance",
        "php",
        "jit"
    ],
    "misconception": "Enabling JIT always improves PHP application performance — typical CRUD web applications are I/O bound; JIT only helps CPU-bound workloads that spend significant time in computation.",
    "why_it_matters": "Understanding when JIT helps (CPU-bound: image processing, ML, simulations) vs when it doesn't (I/O-bound: typical web CRUD) prevents cargo-culting JIT configuration without benefit.",
    "common_mistakes": [
        "Enabling JIT without benchmarking — JIT adds memory overhead; verify it actually improves your specific workload.",
        "Expecting JIT to fix slow database queries — JIT only affects CPU execution time, not network and disk I/O.",
        "Not setting opcache.jit_buffer_size — JIT silently disabled without a buffer allocation.",
        "Conflating OPcache (always beneficial) with JIT (workload dependent)."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "php_jit",
        "opcode_caching",
        "garbage_collection",
        "profiling"
    ],
    "prerequisites": [
        "php_jit",
        "bytecode_vm",
        "aot_vs_jit"
    ],
    "refs": [
        "https://wiki.php.net/rfc/jit"
    ],
    "bad_code": "; php.ini — JIT enabled for typical web CRUD app:\nopcache.jit=1255\nopcache.jit_buffer_size=256M\n; Web app spends 95% of time in MySQL queries\n; JIT improves the 5% PHP execution — negligible real-world improvement\n; 256MB memory wasted on unused JIT buffer",
    "good_code": "; php.ini — JIT for CPU-bound workload (image processing, ML inference):\nopcache.jit=1255          ; Tracing JIT\nopcache.jit_buffer_size=128M\n; Benchmark first: wrk -t4 -c100 -d30s http://localhost/\n; Compare: with/without JIT on your specific workload\n; For typical CRUD: keep jit_buffer_size small or disable JIT entirely",
    "quick_fix": "PHP JIT currently helps CPU-bound code most — benchmark with opcache.jit=tracing vs disabled; if you see <5% improvement on your web workload, the overhead isn't worth enabling",
    "severity": "info",
    "effort": "medium",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/jit_compilation_deep",
        "html_url": "https://codeclaritylab.com/glossary/jit_compilation_deep",
        "json_url": "https://codeclaritylab.com/glossary/jit_compilation_deep.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": "[JIT Compilation](https://codeclaritylab.com/glossary/jit_compilation_deep) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/jit_compilation_deep"
            }
        }
    }
}