Skip to content

Performance: Reduce JIT compile-time overhead (target under 50ms cold start) #94

Description

@PurHur

Problem

README notes ~0.2s baseline to parse and compile a file in bin/jit.php. For web requests, compile-on-every-run dominates unless using AOT (phpc build / phpc serve --aot).

examples/001-SimpleWeb benchmark table shows bin/jit.php ~0.11s vs ./compiled ~0.0016s runtime — production path is AOT; JIT cold compile still matters for #207 phpc serve --jit and dev workflows.

Goal

Measurable compile-time reduction for typical single-file web scripts (<200 lines), targeting <50ms cold compile on reference hardware (document baseline in issue/PR).

Implementation hints

Measure first

Script Purpose
script/bench-compile.php (new) Split timings: parse → CFG → opcodes → LLVM emit → link
make bench Extend or document JIT compile column separate from runtime

Profile hot paths:

  • lib/Compiler.php — avoid redundant recompilation of unchanged files
  • lib/JIT.php — module creation, PHPLLVM context init
  • lib/JIT.pre / opcode lowering

Optimization ideas (prioritized)

  1. On-disk module cache — coordinate JIT: On-disk compile cache for warm requests #153 (phpc cache dir keyed by sha256(file)+compilerVersion)
  2. mtime short-circuit — skip LLVM if source + deps unchanged
  3. Shared stdlib JIT object — precompile ext/standard hot builtins once per process
  4. Lazy block compile — defer cold blocks until executed (larger change)
  5. Self-host — long-term README vision; out of scope for first PR

Deployment guidance (docs)

Acceptance criteria

script/bench-compile.php prints before/after table for examples/001-SimpleWeb/example.php in README or comment on this issue.

Target: documented reduction (e.g. 200ms → <50ms) OR explicit rationale why target deferred (with #153 cache as recommended path).

Verification (local / Docker only)

docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev php script/bench-compile.php

No GitHub Actions.

Dependencies

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions