Skip to content

Release 0.18.0: faster Laravel hot paths, split generated dispatch, symfony-demo serves every page - #605

Merged
blacktrs merged 13 commits into
mainfrom
perf/laravel-hot-paths
Nov 9, 2026
Merged

blacktrs merged 13 commits into
mainfrom
perf/laravel-hot-paths

Conversation

@blacktrs

@blacktrs blacktrs commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Release 0.18.0: faster Laravel hot paths, smaller generated dispatch, symfony-demo serves every page again

Why

After #602 Laravel served without per-request leaks, but profiles showed avoidable work on every request (property visibility checks, get_object_vars, getcwd), and the largest functions clang had to hold were generated dispatchers carrying every class's body inline. symfony-demo, which compiled and served every page at #599, crashed on its first request on main.

What changes

Runtime hot paths (Laravel)

  • Property access check ($o->$name visibility) answers by binary search over a per-class sorted table instead of a strcmp chain.
  • get_object_vars / (array) of an erased object: one small function per class behind a class-id switch.
  • getcwd() answers from the cwd cache chdir() already maintains (libc getcwd(3) opens directories on macOS; the HTTP server asked per request).

Generated dispatch split into small functions (no generated function grows with the class count any more)

  • __mc_static_callable: a function per class (was 308K IR lines in Laravel); no $mono$ copy of synthesized dispatchers.
  • Erased clone: class-id switch + function per class (178K).
  • Erased spread calls (new $c(...$args)): one out-of-line argument unpack per callee (2 x 165K).
  • class_uses: data, not code (155K). unserialize / newInstanceWithoutConstructor: one shared allocation by name, static map + integer tree (2 x 128K).
  • Dynamic spread fallback: name tree + function per arm (104K).
  • print_r / var_export: buckets of at most 64 classes (107K / 76K). constant() / defined(): static name map instead of an O(n) chain of string compares (66K).

Correctness fixes found on symfony-demo (all present on main)

  • The shared erased-invoke helper was built under the prelude frame of whichever site asked first, which strips the variadic pack / default pad arms: every erased call of a ...$args closure got its first argument as the pack (EventDispatcher listeners, crash on the first request).
  • A generator foreach that unsets from the array it walks kept its snapshot in an alloca that died at the resume: the loop end released stack garbage (ArrayAdapter::generateItems, first Doctrine metadata lookup). The snapshot / owned iterable now live in the generator frame and are released when a suspended generator is destroyed.
  • Backtrace frames reached through trampolines ($o->$m()) and through method calls rewritten on the spot (__call split) had a synthetic or zero line; ux-live-component reads the template line from the trace (/en/blog/search answered 500).

Version: COMPILER_VERSION 0.18.0 (bootstrap stays 0.17.0 — no new syntax or builtin used in src/).

Measurements (macOS arm64, -O2, 1 process, wrk c=8)

Laravel route 0.17 + #602 this PR
/api/ping 4148 rps 5290 rps (+28%)
/hello 2596 rps 3047 rps (+17%)
/api/notes 62 rps 98 rps (+58%)

Peak memory of one clang part while building Laravel / symfony-demo: 3.3–3.7 GB.

symfony-demo: /en, /en/blog/, /en/blog/page/2, /uk/blog/, /en/blog/search (also ?q= and XHR), a post, /en/blog/rss.xml, /en/login answer 200, /en/admin/post/ 302, unknown path 404; 60 sequential requests stable.

Tests

Fixes #575 (its repro now passes: promoted to tests/aot/cases/uncaught_variadic_handler_dynamic_spread.php; SIGSEGV on main).

New: dyn_prop_access_denied_many_names, getcwd_follows_chdir, variadic_closure_erased_after_prelude_site, uninit_by_name_many_classes, generator_foreach_unset_snapshot, dump_dispatch_many_classes, trace_line_through_magic_and_dynamic_calls — the crash/trace ones are red on main. Targeted groups (gen, closure, dyn, prop, clone, serial, print_r, var_export, constant, defined, trace, variadic, reflection, spl, iterator, unserialize, enum, object) green.

New issues found on the way: #603 (class_exists family case-sensitive for a runtime name), #604 (constant() on an undeclared class: wrong error message).

Not in this PR

  • symfony-demo per-request leaks (/en/blog/ ~420 KB/request) — separate epic.
  • symfony-demo under concurrent load (shared kernel across request fibers) — known, separate.

Owed before merge

Full AOT suite, difftest, Linux gate.

…ted table per class instead of a strcmp chain: it ran on every $o->$name and was a quarter of a Laravel /api/notes request
… class behind the dispatcher switch instead of every class's property walk inlined in one function (360K IR lines in a Laravel build)
…wd(3) opens directories on macOS, and the HTTP server asked it per request (7% of a Laravel /api/ping)
…ery caller's shape, and __mc_static_callable's $mono$ clone was another 308K IR lines in a Laravel build
… arm

The largest functions clang held in a Laravel build were generated dispatch with
every class's body inline: __mc_static_callable (308K IR lines), __mir_clone_erased
(178K), the erased spread-call arms (2x165K), class_uses (155K), __mc_unser_alloc
and __mc_refl_alloc (128K each), __mc_dyn_spread_fallback (104K).

- __mc_static_callable: each class's method tree is its own function
- erased clone: a class-id switch calling one function per class, not a chain of
  descriptor compares over every class
- vdisp arm spread unpack: one out-of-line fill per callee (not for by-ref params)
- class_uses: data (a static map of trait users + a set of the other names)
- unserialize / newInstanceWithoutConstructor: one shared allocator per class
- dynamic spread fallback: a name tree over per-(class, method) functions
…ude frame of the site that asked first

The variadic pack and default pad arms are kept out of linkonce_odr prelude
bodies. The shared __mir_erinv_* helper (hidden, per module) inherited that rule
from whichever site built it first: in symfony-demo that was the prelude
CallbackFilterIterator::accept, so every erased call of a variadic closure lost
its pack - EventDispatcher's optimized listener (...$args) took the event object
as its pack and the first request crashed in __mir_array_compact.
…ceWithoutConstructor: a static name map and an integer tree instead of two crc32/string-compare trees (2 x 112K IR lines in a Laravel build)
A foreach whose body unsets from the array it walks iterates a copy, and a
foreach over a fresh array owns it. Inside a generator both owners were allocas,
dead after the resume switch: the loop end released stack garbage (symfony-demo's
ArrayAdapter::generateItems, the first Doctrine metadata lookup, SIGSEGV in
__mir_array_release). They now live in frame slots, and a generator destroyed
while suspended in such a loop releases them, as a return would.
…defined() into a name map

print_r and var_export switched over every class in one function (76K and 107K IR
lines in Laravel); they now pick a bucket of at most 64 classes by id range, each
bucket its own function. constant() and defined() were a chain of string compares
over every admitted name - O(n) per call and 66K IR lines; now a static name map
and a bucketed integer tree.
…hod calls

A dynamic $o->$m() reaches the method through a synthesized trampoline, which
pushed the frame with its own synthetic line and whatever file was being lowered
when it was made; the site now leaves its line and file in two slots the
trampoline's push takes. A method call emitted as other method calls built on
the spot (the __call / plain split, dynamic arms) gave those calls line 0; they
now take the line of the call they stand for. ux-live-component reads the
template line off the trace: symfony-demo /blog/search answered 500.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A variadic closure forwarding to $this->{$m}(...$args), installed as the exception handler, crashes (SIGBUS) when an exception is uncaught.

1 participant