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
perf: drop per-request weak_ptr lock() in gated hook-fire helpers
The three tail-end hook-fire helpers each locked the request's
resource_weak_ BEFORE checking their any_hooks_ gate, so every matched
request paid ~8 atomic RMWs on the resource's shared control block (3x
weak_ptr::lock() CAS + 3x shared_ptr destruction, plus the weak assign
/destroy) even with zero hooks registered -- the common case, and worse
under thread-pool load where all workers hammer the same cache line.
Master's dispatch used raw http_resource* with no refcount traffic; this
also contradicted TASK-051's plan ("one pointer null-check per phase").
fire_after_handler_gated and fire_response_sent_gated both fire within
finalize_answer's scope, where the owning shared_ptr (hrm) is still
alive, so they now take the resolved http_resource* directly and read
hook_table_raw_() from it -- no lock(). The resource is threaded through
materialize_and_queue_response for the response_sent site (nullptr on the
skip-handler / 404 paths, which both helpers already tolerate).
fire_request_completed_gated genuinely fires from the MHD completion
callback, after that shared_ptr is gone, so it keeps the weak_ptr lock()
-- but gated behind a new modded_request::route_has_hook_table_ snapshot
(taken in finalize_answer). When no per-route hook table existed at
dispatch and no server-wide request_completed hook is registered, the
lock is skipped entirely; when the snapshot is set it still locks and
runs the precise any_hooks(request_completed) check, preserving the
unregistration-skip contract.
Net on the zero-per-route-hook path: from ~8 control-block atomics per
matched request down to the 2 (resource_weak_ assign + destroy) that the
handler_exception path independently requires. No behavior change beyond
the same same-request-registration race the relaxed any_hooks_ gates
already tolerate. Full suite green (109/109).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NpysYDDJac63yz2mZKKiDf
0 commit comments