You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Throwing and catching an exception is ~44× slower than php (20 µs vs 0.47 µs) #648
Exceptions are ordinary control flow in real applications: Symfony routing throws NotFoundHttpException for every 404, Laravel validation throws ValidationException, Doctrine and Guzzle throw on expected failures. A request path that throws a handful of times pays tens of microseconds each.
It is also the single largest cost in the AOT suite's serial phase: the throw-path leak tests spend 9–14 s each in 200k throws.
Expected
A throw/catch within a few frames costs on the order of php's (single-digit µs at most).
Notes
Zero-cost exceptions unwind through the platform unwinder (two-phase search + cleanup per frame); every frame between throw and catch with a landing pad is visited twice, and the personality runs per frame. Backtrace capture on construction may add to it.
Measured on Linux arm64 (Ubuntu LTS VM, manticore 0.18.0 release): 1.35 µs per throw, flat from a same-function catch to five frames deep — 2-4× php, not 44×. The 20 µs is macOS-only.
macOS cause (sample): every throw starts unwinding inside the system _Unwind_RaiseException, i.e. at a frame of libunwind.dylib in the dyld shared cache. libunwind asks _dyld_find_unwind_sections for that address and dyld4 resolves shared-cache addresses with findImageMappedAt → forEachImageTextSegment, a linear walk over the cache's images. ~70% of the time is that lookup; it happens again in every _Unwind_Resume a cleanup pad calls.
Fix direction for macOS: raise and resume through libunwind's unw_getcontext/unw_init_local/unw_step API from our own image, calling __mc_personality for both phases ourselves, so no step ever starts inside the shared cache; cleanup pads end in our resume instead of _Unwind_Resume. Linux keeps the libgcc path.
Activity
blacktrs commentedon Nov 11, 2026
Measured on Linux arm64 (Ubuntu LTS VM, manticore 0.18.0 release): 1.35 µs per throw, flat from a same-function catch to five frames deep — 2-4× php, not 44×. The 20 µs is macOS-only.
macOS cause (
sample): every throw starts unwinding inside the system_Unwind_RaiseException, i.e. at a frame of libunwind.dylib in the dyld shared cache. libunwind asks_dyld_find_unwind_sectionsfor that address and dyld4 resolves shared-cache addresses withfindImageMappedAt→forEachImageTextSegment, a linear walk over the cache's images. ~70% of the time is that lookup; it happens again in every_Unwind_Resumea cleanup pad calls.Fix direction for macOS: raise and resume through libunwind's
unw_getcontext/unw_init_local/unw_stepAPI from our own image, calling__mc_personalityfor both phases ourselves, so no step ever starts inside the shared cache; cleanup pads end in our resume instead of_Unwind_Resume. Linux keeps the libgcc path.Build @serial cases in the parallel pool and run only their measureme…
Darwin: 6x faster throw/catch; @serial test cases build in parallel (#…