Repository navigation
Darwin: 6x faster throw/catch; @serial test cases build in parallel - #649
Merged
Merged
Conversation
…image, one pass The system _Unwind_RaiseException/_Unwind_Resume start from a frame inside libunwind.dylib, an address dyld resolves by walking every image of the shared cache: ~20 us per throw and again per cleanup pad. The runtime now drives the unwind itself (unw_getcontext/unw_step/unw_resume), asking each personality to search and then to install a handler or a cleanup pad in the same pass; cleanup pads end in @__mc_resume. One pass is enough because a PHP throw runs every unwound frame's cleanups whether or not it is caught. The cursor is zeroed first: unw_resume pops the cursor's walked-frame count off the return stack. Throw+catch on macOS arm64: 19.6 us -> 3.1 us. Linux is unchanged.
…nt alone; cut the throw-leak tests to 20k iterations A @serial case needs a quiet machine for its RUN, not for its build: the runner now compiles it with the others (`@c:<name>`, MC_PHASE=compile) and the serial loop only runs the binary (MC_PHASE=run). The four throw-path leak tests added for #647 did 100-200k throws (9-13 s each at today's cost of a throw, #648); 20k iterations with a 5 MB threshold still catch the leak they guard.
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.
Part of #648.
Problem
On macOS a caught PHP throw cost ~20 µs (php: 0.3–0.6 µs, Linux build: 1.35 µs).
sampleshows ~70% inside dyld: the system_Unwind_RaiseException/_Unwind_Resumestart from a frame in libunwind.dylib, and dyld resolves shared-cache addresses by walking every cached image — once per throw and again per cleanup pad.Change (Darwin only; Linux untouched)
@__mc_unwindruns the unwind through libunwind'sunw_getcontext/unw_step/unw_resumestarting in our image.CLEANUP|HANDLER_FRAME) or the frame's cleanup pad. A PHP throw runs every unwound frame's cleanups caught or not, so the search phase only chose where to stop. End of stack = the uncaught fatal.@__mc_resume(foreign or forced unwinds fall back to_Unwind_Resume).unw_init_local:unw_resumepops the cursor's walked-frame count off the return-address stack, and stack garbage there spun for billions of iterations.Result
throw+catch, macOS arm64: 19.6 µs → 3.1 µs. The remaining cost is dyld's lookup of our own image per step; the error-return model (design on branch
exc-error-return) removes it on both platforms.Testing
Also: faster test runner
tests/aot/run.sh:@serialcases are now compiled in the parallel pool (MC_PHASE=compile); only their measurement runs alone (MC_PHASE=run). Full macOS suite 472 s → 458 s, same verdicts.