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_SAFE so schedulers can execute them in a worker pool through blocking_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_SAFE is 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.
Configuration
Before
After
Four workers: batch time
3.062 s
0.775 s
Four workers: hashes/second
20.9
82.6
Four workers: timer delay
378.98 ms
0.77 ms
One worker: hashes/second
20.9
20.8
One worker: timer delay
379.79 ms
1.63 ms
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.
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
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_SAFE so schedulers can execute them in a worker pool through blocking_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_SAFE is 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