Repository navigation
Front-end, emitter and build sweep: Laravel lowering 128 s -> 25 s, staged IR -42%, peak RSS -30%, bin/build 12 -> 1.5 min - #510
Conversation
…lare (O(N^2) rebuild per synthesized function; Laravel lowering 128 s -> 29 s)
…canning every function per class/method (Laravel InferTypes 50 s -> 8-17 s per full run)
…e instead of scanning per name
…ass census index, scan closedness with PCRE
…file path reads bodies up to 64 MB whole
…method site so it takes the shared dispatch
… across many classes
…y holder name to the shared helper (Laravel IR 4.20 -> 2.89 GB)
…two blocks per call site (symfony-app IR -10%)
…or by default The compiler's pass-1 build was one serial `clang -O2` over ~200 MB of IR: ~10 min and a ~7.7 GB peak (the middle end plateaus near 2.8 GB, the backend ramps past 7 GB). Auto-split (19 parts) takes ~1.5 min at ~4 GB. Measured on the same commit, symfony-app front+emit, 6 interleaved runs per variant: the split costs the compiler itself +4.5% (62.9 s vs 65.7 s wall, 62.6 s vs 65.4 s CPU). The emitted IR is identical either way. The compiler was also built without its automatic cycle collector. On Laravel (-O 0, compiler process only) the collector takes the peak RSS from 6.5 GB to 4.7 GB (after the parse step 667 MB to 155 MB) for +4.7% time (340 s to 356 s). Both are now the default; MANTICORE_AUTO_SPLIT=0 and MANTICORE_AUTO_GC=0 restore the old build.
…ly (29 s -> 0.3 s on Laravel's extra helpers); phase timing lines for the end of emit
…eamble to a file instead of passing 237 MB up through four string concatenations (Laravel peak RSS 5.0 -> 4.5 GB)
|
@claude please review |
|
Claude finished @blacktrs's task in 1m 31s —— View job Review of #510: front-end, emitter and build sweepI read the full diff and the surrounding code for the riskiest paths. I did not build or run anything, so this is a code read only. The changes are mostly sound: each indexing fix keeps the old semantics, and the identical symfony-app IR is good evidence for the pure-speed ones. These are the points I'd look at, most important first. 1.
2. The
3. Preamble spooling (
4.
5.
6.
7.
8.
9. Dyn-method spread sharing (
10. Process and docs
Tests: the three new cases are good. Their Bottom line: I found no correctness bug I could prove from the diff. Items 1 and 2 are the ones most likely to quietly undo the speedups. Item 3 (marker and cleanup fragility) and the missing full-suite and gate runs are what I'd resolve before merging. |
…ship, runFast differential tool - LowerReify::findFunctionDef: a name the index does not hold is not in the list (the index covers every entry up to the current count); chainMethodFn probes Class__method up the parent chain and most probes miss, so a miss must not fall back to the linear walk. Only a slot that no longer holds its name walks. - EmitLlvm: a failed build no longer leaves preamble spool files behind (dropPreambleSpools), and the assumption that a spool starts a line is checked when the marker is expanded instead of assumed; linkonceRuntime's doc comment is back above its method. - Main: the stale-builder sweep only touches entries owned by the current user. - LowerFromAst: drop the now-unused variadicMethodParamsCache. - tools/hoist_diff.php: differential check of HoistAllocas::runFast against run() over real IR and a scrambled copy of it (153 variants, 127 011 allocas moved, no mismatch). - Repro tests/aot/repro/wrong/spread_byref_array_writeback (#511): a by-ref parameter reached through a spread of an array passed by reference does not write back; the same on main, found while checking the dynamic-method spread path.
|
Thanks for the review. Point by point, with what I checked and what I changed (pushed as
|
session_start() rolls session.gc_probability / gc_divisor (1/100 by default) and calls the handler's gc() on a hit. The test pins the handler protocol, which has no gc, so one run in a few hundred printed an extra `gc(1440);` (8 of 3000 local runs; failed once on linux-alpine-arm64 in CI). Set session.gc_probability to 0 in the test, as php's own session tests do; 0 of 3000 runs now differ.
|
The |
…f one The probe reads the peak RSS, which moves in whole pages for reasons that are not a leak; a single 40 000-call batch occasionally crossed the 200 KB budget on one CI job (viaArr printed `leak`) while the identical code on every other target stayed flat. A real per-call leak grows every batch, so the function is now flat if any of three consecutive batches stays within the budget. A deliberately leaking variant still prints `leak`.
|
|
What
A compile-time and memory sweep of the front end, the emitter and the build of the compiler itself, found by profiling a Laravel application (4 652 files, 132 k functions) and
examples/symfony-app. Every fix removes a linear scan inside a loop, an avoidable copy of a multi-hundred-MB string, or a block of IR that every later phase has to write, split and parse.Laravel,
-O 0, up to the assembly step (numbers are from my runs on a loaded machine, ±10%):LowerFromAstInferTypes(one full run)MonomorphizeEmitLlvmbin/build(compiler self-build)Changes, by area
Lowering / inference (time)
LowerFromAst::canonFunctionNamerebuilt its case-insensitive function index on every declared function (O(N²), 99 s on Laravel): the index is now updated on declare.variadicMethodParamsandLowerReify::findFunctionDefwalked every class / function per name: indexed once.InferTypes::scanCtorPropContainerswalked all functions per class (5.5 billion steps) andanyDeclarerFncopied every function name per method: both indexed once per run.Emitter (time)
emitDynFnCallfiltered 130 k signatures per dynamic-call site, three times: candidate sets are shared per arity.classCensusIndexmemoized;irIsClosedscans with PCRE instead of a per-byte loop.HoistAllocas::runFastslices a function body instead of walking lines (about 2x on the in-memory path) and searches only inside the body;SplitModulecollects@symbolreferences per body with one PCRE pass (88 s -> 69 s).IR size
$o->$m(...$pack)handed every by-ref / variadic name to inline arms over the caller's argument nodes, once per late-static-binding copy of the forwarder (Laravel'sFacade::__callStatic: 268 names x 46 copies). A single spread of a cell-element pack now shares the helper: -1.3 GB.new $cls(...)and closure literals are hoisted out of a dynamic-method site so it takes the shared dispatch (a 28 MB function in Eloquent): -243 MB.print_r/var_exportproperty lines are one call instead of an inlined concatenation; backtrace push/pop arealwaysinlinehelper calls instead of two blocks per call site (symfony-app IR -10%).Memory
linkonce_odrrewrite applied, instead of being copied up through four string concatenations: -0.5 GB peak.bin/buildkeeps the compiler's automatic cycle collector (peak 6.5 -> 4.7 GB for +4.7% time) and splits the compiler's own module (see below).Build
bin/buildsplit the compiler's module by default. One serialclang -O2over ~200 MB of IR took ~10 min and ~7.7 GB. Measured on the same commit,symfony-appfront end + emit, six interleaved runs per variant, bothMANTICORE_AUTO_GC=0: the split costs the compiler itself +4.5% (62.9 s vs 65.7 s wall, 62.6 s vs 65.4 s CPU). Emitted IR is identical.MANTICORE_AUTO_SPLIT=0/MANTICORE_AUTO_GC=0restore the old build.buildsweeps/tmp/manticore_buildobj_<pid>.*left by dead builders (killed builds left 4 GB each; 50 GB accumulated in a day).Verification
examples/symfony-appstaged IR is byte-identical before and after (cmp, sha3a9458c1...); Laravel's staged IR has the same byte count.dyn_method_new_dyn_arg,dyn_method_spread_forward,dyn_method_arm_helpers(outputs fromphp).rm bin/manticore; bin/build, stage0 0.17.0 -> generation 1 -> generation 2): green.tests/aot/run.sh -ksubsets, all green:hello,dyn(121),closure,backtrace,exception,generator,spread,reflect,print_r,var_export,serialize,static,callable;tests/cliandtests/parsergreen.examples/symfony-appbuilt with the result:/200, 404, 20 requests;APP_ENV=devwith a coldvar/(previously crashing) serves 200/404.Not run: the full AOT suite,
tools/difftest.sh,tools/selfhost_fixpoint.sh, the Linux gate. Laravel itself does not run yet, so its numbers are compile-side only.Notes for review
InferTypes,EscapeSummariespooling). They follow once those land.