Skip to content

Replace a registry on registration instead of writing into it - #2976

Merged
ericproulx merged 1 commit into
masterfrom
registry-frozen-copy-on-write
Sep 20, 2026
Merged

ericproulx merged 1 commit into
masterfrom
registry-frozen-copy-on-write

Conversation

@ericproulx

Copy link
Copy Markdown
Contributor

A registry is written when a formatter, parser, params builder, validator or versioner class is defined, and from then on it is only ever looked up — on the request path, at that: once per response by Grape::Formatter, once per parsed body by Grape::Parser, once per params build by Grape::ParamsBuilder.

Have register build the next Hash and freeze it, rather than writing into the one readers hold. Nothing can find a registry changed underneath it, and nothing can write to one without going through register.

Notes:

  • Registration still lands under both the String and the Symbol spelling, and still warns when it overrides an existing short name — the registry is replaced, not appended to, so a re-registration overrides exactly as before.
  • spec/support/deregister.rb, the spec-only helper that undoes a registration, replaces the registry in turn. No unregister is added to the library.
  • Two examples pin that a registry is frozen both before and after anything is registered.
  • Also a prerequisite for serving a compiled API from non-main Ractors, which cannot read a class ivar holding an unshareable value — a frozen Hash of classes they can read.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Sep 20, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

@ericproulx
ericproulx force-pushed the registry-frozen-copy-on-write branch 3 times, most recently from a9cefbc to 69842b8 Compare September 20, 2026 20:46
A registry is written when a formatter, parser, params builder,
validator or versioner class is defined, and from then on it is only
ever looked up -- on the request path, at that, once per response, per
parsed body or per params build.

Have register build the next Hash and freeze it, rather than writing
into the one readers hold. Nothing can find a registry changed
underneath it, and nothing can write to one without going through
register. The spec-only deregister helper replaces the registry in turn.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ericproulx
ericproulx force-pushed the registry-frozen-copy-on-write branch from 69842b8 to 87e20f6 Compare September 20, 2026 21:05
@ericproulx
ericproulx merged commit c69a0cb into master Sep 20, 2026
69 checks passed
@ericproulx
ericproulx deleted the registry-frozen-copy-on-write branch September 20, 2026 21:08
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