GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allow fiber schedulers to offload bcrypt operations by samuel-williams-shopify · Pull Request #304 · bcrypt-ruby/bcrypt-ruby

Conversation

@samuel-williams-shopify

@samuel-williams-shopify samuel-williams-shopify commented Sep 27, 2026

Copy link
Copy Markdown

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.

Validation

  • Ruby 4.0.7 and 3.4.4: 44 examples, 0 failures.
  • Ruby 3.3.1: 44 examples, 0 failures, 5 offload-specific examples skipped.
  • All five offload specs fail against the unmodified extension because its callbacks never reach the scheduler.
  • Every benchmark hash is checked against an expected result.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@samuel-williams-shopify
Allow bcrypt operations to be offloaded by fiber schedulers
8ec0ae3
@samuel-williams-shopify

samuel-williams-shopify commented Sep 27, 2026

Copy link
Copy Markdown
Author

cc @ekmartin

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@samuel-williams-shopify
Benchmark bcrypt with Async scheduler worker pools
85c1580
@samuel-williams-shopify
samuel-williams-shopify force-pushed the offload-safe branch from 03f6a15 to 85c1580 Compare September 27, 2026 21:47

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@samuel-williams-shopify
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.