Skip to content

php-in-php: base64_encode()/base64_decode() JIT via Base64JitHelper PHP — drop inline LLVM in JitBase64*.php (#1492) #17234

Closed

Description

@PurHur

Category

php-in-php · runtime-shrink / JIT LLVM → Vm PHP

Problem

ext/standard/JitBase64Encode.php (~204 lines) and JitBase64Decode.php (~233 lines) embed inline LLVM for RFC 4648 base64, duplicating VmString::base64_encode() / VmString::base64_decode() (landed in #978).

Sibling string builtins (bin2hex, hex2bin, …) already route through PHP JitHelpers + lib/JIT/Builtin/String* bridges.

php-src reference

PHP implementation target

  • ext/standard/Base64EncodeJitHelper.php — SSOT delegating to VmString::base64_encode()
  • ext/standard/Base64DecodeJitHelper.php — SSOT delegating to VmString::base64_decode() (runtime JIT path: non-strict empty-string on failure, matching current LLVM)
  • lib/JIT/Builtin/StringBase64Encode.php / StringBase64Decode.php — thin __compiler_base64_* bridges via nested JIT
  • lib/JIT/Builtin/StringBase64*Llvm.php — user-script AOT defer (Stdlib/AOT: standalone binary run segfault (exit 139) after compile — Docker harness JIT-linked builtins #16734)
  • Shrink ext/standard/base64_*.php call() — route through bridges; retain JitBase64*.php LLVM only for defer path

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "
echo base64_encode(\"foo\"), \"\\n\";
echo base64_decode(\"Zm9v\"), \"\\n\";
"'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter Base64'

Done when

  • Runtime JIT/AOT base64 routes through Base64*JitHelper PHP (not inline LLVM in hot path)
  • Base64RuntimeShrinkTest guard + existing base64_* compliance green VM+JIT+AOT
  • Spine includes helpers + bridges; php script/check-selfhost-spine-coverage-sync.php OK
  • PR notes LLVM lines removed from hot path

Refs #978, north star #1492

Activity

  1. added
    enhancementNew feature or request
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 7, 2026
  2. PurHur commented on Jul 7, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run.

  3. PurHur commented on Jul 7, 2026

    @PurHur
    OwnerAuthor

    Merged via #17236

    Runtime shrink: hot-path JIT/AOT for base64_encode() / base64_decode() now routes through Base64EncodeJitHelper / Base64DecodeJitHelper → VmString via StringBase64Encode / StringBase64Decode nested-JIT bridges. Inline LLVM in JitBase64Encode.php (204 LOC) / JitBase64Decode.php (233 LOC) retained only for user-script standalone AOT defer (#16734).

    Verification:

    • vendor/bin/phpunit --filter Base64RuntimeShrinkTest — OK (4 tests)
    • vendor/bin/phpunit --filter "Base64BuiltinTest|Base64RuntimeShrinkTest" — OK (6 tests, VM+AOT smoke)
    • php bin/vm.php -r 'echo base64_encode("foo"), "\n"; echo base64_decode("Zm9v"), "\n";' — Zm9v / foo
    • php script/check-selfhost-spine-coverage-sync.php — OK
    • make bootstrap-selfhost-vm-driver-execute-probe — OK
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

    area:compilerCompiler / CFG / JITenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevEx

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions