Allow fiber schedulers to offload bcrypt operations - #304
Open
samuel-williams-shopify wants to merge 2 commits into
Open
samuel-williams-shopify wants to merge 2 commits into
samuel-williams-shopify wants to merge 2 commits into
Conversation
Author
|
cc @ekmartin |
samuel-williams-shopify
force-pushed
the
offload-safe
branch
from
September 27, 2026 21:47
03f6a15 to
85c1580
Compare
This branch has not been deployed
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.
Bcrypt releases the GVL during salt generation and hashing, but these operations still block the calling fiber scheduler's thread. Mark both native callbacks with
RB_NOGVL_OFFLOAD_SAFEso schedulers can execute them in a worker pool throughblocking_operation_wait.Both callbacks use frozen input strings and per-call output buffers, do not call Ruby APIs, and do not depend on the calling thread's state. The existing implementation remains the fallback when
RB_NOGVL_OFFLOAD_SAFEis unavailable.Includes regression specs for scheduler dispatch, known hash results, native failure results, and input lifetime and mutation during scheduler handoff. Also includes an Async benchmark, reproduction instructions, and all 30 measurement samples.
Benchmark
64 cost-10 hashes across eight Async tasks on an Apple M4 Pro, Ruby 4.0.7, Async 2.46.0, and io-event 1.22.1. Values are medians of five runs; timer delay is the median of each run's maximum delay for a 5 ms heartbeat.
Four workers provide 3.95× throughput in this workload. One worker preserves throughput while keeping the event loop responsive. The unmodified extension submits zero operations to the pool; the modified extension offloads all 64 hashes per batch. Throughput remains similar with the pool disabled.
Validation