Performance improvements in class_methods.rb#32
Merged
guille-sage merged 1 commit intomasterfrom Feb 17, 2026
Merged
Conversation
Makes a series of performance improvements to the methods defined by `#attr_accessor_type`. In most cases this will make the initial loading when defining a class a bit slower but make parsing and dumping faster. - Use a shared ValueHelper singleton that is shared by all closures - Remove calls to #get_attribute: use the cka closure directly - Pre-compute getter and setter symbols (:"@name" and :"@name=") - Define smaller methods, changing the logic depending on the type and other things known at definition time. This makes the runtime checks leaner. For example, the old code generated methods that had to check on every run whether the attribute was `one_of`. This is solved by checking before defining the method.
PawelKlapec
approved these changes
Feb 17, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Makes a series of performance improvements to the methods defined by
#attr_accessor_type. In most cases this will make the initial loading when defining a class a bit slower but make parsing and dumping faster.one_of. This is solved by checking before defining the method.Already showing decent improvements in the benchmarks: