Skip to content

Generate a method for each key on first use - #73

Merged
jho406 merged 1 commit into
mainfrom
gen-methods
Oct 18, 2026
Merged

jho406 merged 1 commit into
mainfrom
gen-methods

Conversation

@jho406

@jho406 jho406 commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Every json.key value went through method_missing, a failed lookup that YJIT cannot cache. method_missing now defines a real method for the key the first time it sees it, following Active Model's attribute methods: generated methods live in their own module, only plain method names are generated, and existing methods are never redefined.

Every `json.key value` went through method_missing, a failed lookup that
YJIT cannot cache. method_missing now defines a real method for the key
the first time it sees it, following Active Model's attribute methods:
generated methods live in their own module, only plain method names are
generated, and existing methods are never redefined.

Definition happens under a mutex. Defining without one is safe on CRuby:
a 16-thread stress test with the race forced only redefined identical
methods, printing "method redefined" with warnings on. Without Ractors,
only the GVL prevents two definitions at once, on 4.0 as well, so the
lock makes that explicit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jho406
jho406 merged commit e8b05d4 into main Oct 18, 2026
24 checks passed
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