Skip to content

AOT: split user-script builds into cached runtime TU + script TU — ~50% of every phpc build re-lowers identical JitHelpers (lib/Runtime.php) #15889

Description

@PurHur

Category

performance · AOT compile pipeline

Problem

Every phpc build recompiles the fixed runtime helper set from scratch. Phase profile of phpc build -o /tmp/hello examples/000-HelloWorld/example.php (php-compiler:22.04-dev, LLVM 9, breadcrumb polling via PHP_COMPILER_JIT_PROGRESS_FILE, 2026-07-04, wall 2.66 s):

Phase Wall Share
PHP boot + autoload + JIT context init 0.66 s 25%
user-script parse + lower 0.06 s 2%
runtime JitHelper lowering (WeakRefRegistry, ErrorSilence, DirHandle, ParseStrNative, Progress, … — repeated runtime_parseandcompile_begin cycles) 1.24 s 47%
LLVM emit object 0.61 s 23%
link 0.14 s 5%

The helper set is identical for every user script — none of it depends on user code. Larger web examples pay 5.3 s (006) for the same reason.

Proposal (split compilation into parts)

  1. Cache the runtime TU: lower all JitHelpers once into a versioned build/user-runtime.o (key: compiler tree hash + LLVM version), reuse across builds — the bootstrap path already has the TU-sidecar mechanics (PHP_COMPILER_M3_* emit-helper TUs, prelinked/bootstrap-gen0 blobs); user builds should get the same treatment.
  2. Script TU: lower only {main} + user functions per build; link script.o + user-runtime.o + runtime C objects.
  3. Optional: parallel emit when >1 TU is dirty.

Expected: hello-world ≈ 2.7 s → ≈ 0.9 s (boot + tiny lower/emit + link); web examples similar absolute savings.

Done when

  • Second consecutive phpc build of a different script skips helper lowering (cache hit logged)
  • Cache invalidates on compiler-tree change (hash key), verified by test
  • examples/README benchmark bin/compile.php column drops accordingly
  • benchmarks/README.md phpc-build column regenerated

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