Repository navigation
Call-site binding: read parameter attributes and class getters once per type - #88
Merged
Merged
Conversation
…er type Two reflection lookups at every binding of a call site, both answering the same thing every time for the same parameter or type: - RubyOverloadResolver (2016): ParameterInfo.IsDefined for [DefaultProtocol] (HasExplicitProtocolConversion, Convert) and [ParamArray] - several times per candidate overload, each a walk of the parameter's metadata that allocates. Now one read per parameter, kept in a ConditionalWeakTable. - MetaObjectBuilder.AddTargetTypeTest (2016): type.GetMethod for the ImmediateClass getter and Type.IsVisible, which walks generic arguments and declaring types, for every rule on a Ruby object. Now cached per type, weakly. Bindings are what every new class costs: its call sites miss their rules. In a profile of Struct.new/Class.new, Type.IsVisible was the largest self-time entry (10.9%, two thirds from AddTargetTypeTest) and CustomAttribute.IsDefined another 7.6%. Struct.new(:a, :b, keyword_init: true) + Struct.new(:a, :b) + Class.new, best of 6, Release, net8.0: 828-858 -> 783-817 us (about 5%). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf5xqgL3eZiUCWPfG2b
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
32 of 36 tasks
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.
This PR removes two reflection lookups, both in 2016 code, that run every time a call site is bound. Each lookup answers the same thing every time for the same parameter or type.
RubyOverloadResolvercalledParameterInfo.IsDefinedfor[DefaultProtocol](inHasExplicitProtocolConversionandConvert) and for[ParamArray], several times per candidate overload. Each call walks the parameter's metadata and allocates. Each parameter is now read once and kept in aConditionalWeakTable.MetaObjectBuilder.AddTargetTypeTestcalledtype.GetMethodfor theImmediateClassgetter and checkedType.IsVisible, which walks generic arguments and declaring types, for every rule on a Ruby object. Both are now cached per type, also in a weak table.Every new class pays for bindings, because its call sites miss their cached rules. A profile of
Struct.newandClass.newshowed where that time went:Type.IsVisiblewas the largest self-time entry at 10.9 %, and two thirds of it came fromAddTargetTypeTest.CustomAttribute.IsDefinedtook another 7.6 %.Numbers
The benchmark is one
Struct.new(:a, :b, keyword_init: true), oneStruct.new(:a, :b)and oneClass.newper iteration, best of 6, Release, net8.0. It went from 828–858 to 783–817 µs, about 5 % faster.Loading a set of standard libraries at startup showed no difference that stood out from the noise.
Testing (Linux, net8.0, Release)
Util/run-tests.sh: PASSED, 0 failure lines.languageandcore/{kernel,module,class}: 6,269 examples, 1 failure.core/{struct,data,string,array,hash,integer,proc,method}: 8,726 examples, 1 failure and 19 errors.Generated by Claude Code