Skip to content

Define Grape's callable constants as modules rather than lambdas - #3096

Merged
ericproulx merged 1 commit into
masterfrom
refactor/callable-constants-as-modules
Nov 21, 2026
Merged

ericproulx merged 1 commit into
masterfrom
refactor/callable-constants-as-modules

Conversation

@ericproulx

@ericproulx ericproulx commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Part of making Grape's internals readable from a non-main Ractor, without calling the Ractor API from lib/ (groundwork for #2978). Split from #3095, with the rest in #3097 and #3098.

A proc carries the self it was written under and the variables it closes over, so freezing one does not let a non-main Ractor call it: only Ractor.make_shareable does that. A module is shareable as it is. The four lambda constants become modules answering call, the shape of the formatters Grape registers:

  • Grape::Formatter::DEFAULT_LAMBDA_FORMATTER. A format nothing is registered for raised in a Ractor.
  • Grape::Router::Route::FORWARD_MATCH_METHOD and NON_FORWARD_MATCH_METHOD.
  • Grape::Endpoint::RackStack::RUN_ENDPOINT, private, now RunEndpoint.

The public ones keep their names, and their callers only ever call them.

Throughput

Ruby 4.0.6, 6 rounds from one checkout, alternating which side runs first, median of the per-round ratios. Route matching now calls a module rather than a lambda:

YJIT interpreter
GET, 21 routes −0.2% (3/6 rounds faster) −4.0% (5/6)
a mounted Rack app (forward match) +0.9% (2/6) −1.3% (4/6)

🤖 Generated with Claude Code

A proc carries the self it was written under and the variables it closes
over, so freezing one does not make it shareable; a module is shareable
as it is. DEFAULT_LAMBDA_FORMATTER, FORWARD_MATCH_METHOD,
NON_FORWARD_MATCH_METHOD and RUN_ENDPOINT become modules answering call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ericproulx
ericproulx force-pushed the refactor/callable-constants-as-modules branch from 3332406 to 6fe8e0a Compare November 21, 2026 17:29
@ericproulx
ericproulx merged commit ec09bbb into master Nov 21, 2026
52 checks passed
@ericproulx
ericproulx deleted the refactor/callable-constants-as-modules branch November 21, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant