Repository navigation
Export stdlib dynamic-call thunks from stdlib.o instead of rebuilding them in every program - #335
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
CI got slow: the AOT suite on
linux-amd64went from 19 min (Sep 23) to 91 min (Oct 16). Per-case compile cost roughly doubled while the case count grew ~1.9x. About 87% of a case's compile time isclang -O2 -cover the whole module, and the IR it is handed kept growing (2.6 MB on v0.11 → 6.5 MB on main forfwrite_park_overwrite).The growth is dynamic-call-by-name machinery. Every dynamic-name call site (
$cb(...),callable) built a table of every nameable function that fits its arity, plus onelinkonce_odrthunk per function and arity. With the stdlib ~5x larger, one site expanded to ~970 thunks. The sites that trigger it are mostly in the prelude Async runtime (Scheduler,Fiber::__mcRun,TaskGroup,Semaphore,pcntl_signal_dispatch), so any program touching streams or async paid for it.What changes
The stdlib build now emits those thunks once and exports them from
lib/manticore_stdlib.o:__mc_sdynf<bit>_<fn>: argc 0..8, plus a bare spread over an untyped ormixed[]pack, built from the samedynfThunk/dynfSpreadThunkcode as before;.sigkey,"dynf".A program still builds its own candidate set and table exactly as before. Only a row's target changes: a stdlib import whose shape is exported points at a
declared library thunk instead of a module copy. Prelude and user functions, by-ref inline arms, argc above 8 and spreads with a fixed prefix are built in the module as today. A.sigwithoutdynf(old lib, dev-tree fallback,stdlib:false) builds everything in the module, so no link-time surprises.Name resolution and coercion are untouched.
Measured
19 cases (every 60th of the Sep 23 case list),
-O2 --no-analyze, same worktree before/after:Per affected case:
async_select_reactor6.5 → 4.0 MB,reflection_function3.9 → 2.5 MB,curl_write_callback3.6 → 2.2 MB,http_keepalive_outlives_idle_timer12.4 → 9.4 MB. The 11 cases without thunks are unchanged; hello world is byte-identical.lib/manticore_stdlib.ogrows 7.2 → 8.9 MB.The win is smaller than a full removal because prelude thunks and by-ref inline arms keep large prelude bodies alive (
usort/uksort~195 KB each,array_filter~112 KB). Moving prelude thunks into the library is not safe as is: their bodies arelinkonce_odrand can be specialized per module. That is a separate follow-up.Verification
Targeted groups on macOS, all green:
dyn101,callable30,closure93,spread34,variadic20,fiber14,async51,curl11,http33,reflection56,array_268,func30,stream23.tests/aot/xfail.sh: 61 XFAIL, 0 XPASS.bin/buildreaches a clean finish (pinned release builds the tree, the new compiler rebuildsstdlib.o, 0 CELLGUARD violations).New case
dynf_stdlib_by_namecovers call by name with defaults, case-folded and\-prefixed names, an arity above the export cap, a user spread, a by-ref arm, a user function beside the stdlib fallback, an unknown name, andcall_user_func(_array). It also passes on the baseline compiler; it guards behaviour, since this is a size refactor.Not run: full AOT suite, difftest, fixpoint, Linux gate (arm64 / amd64 / alpine). Linux is the target, so the gate is required before merge.
Found on the way (not fixed here)
array_map($runtimeName, …)SIGBUScallableparameter SIGBUSes (A function-name string read from an array element and passed to acallableparameter SIGBUSes. #252)$f = 'ucfirst'; $f('ab', 3)throws "Call to undefined function" where php throwsArgumentCountError