Performance optimizations and Version#== clarity fix#18
Merged
Conversation
- Memoize Version#to_s and Interval#empty? since both are immutable - Optimize Interval#overlaps? with inline bounds check instead of allocating intersection - Single-pass interval filtering in VersionRange constructor - Use match? instead of match to avoid MatchData allocation - Improve cache eviction to drop oldest half instead of clearing everything - Precompile OPERATOR_PREFIX_REGEX constant in Parser - Add explicit parens in Version#== for clarity - Add benchmark gem for Ruby 4.0.0 compatibility
- benchmark gem is only used in Rake tasks, not at runtime - Replace validate_bounds! and lazy empty? memoization with a single compute_empty called at construction time
Use ObjectSpace.count_objects to measure actual object allocations during cold parsing, cached parsing, and repeated operations instead of hardcoding a ~300 bytes estimate.
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.
Version#to_sandInterval#empty?since both are immutable after constructionInterval#overlaps?with inline bounds check instead of allocating a full intersectionIntervalVersionRangeconstructor (replacecompact.rejectwithselect)match?instead ofmatchin hot paths to avoidMatchDataallocationOPERATOR_PREFIX_REGEXconstant inParser#sort_key_for_constraintVersion#==operator precedence bug (was parsing asself <=> (other == 0)due to==binding tighter than<=>)benchmarkgem for Ruby 4.0.0 compatibility in rake tasksIntervalempty computation (validate_bounds!andempty?were doing the same comparison)ObjectSpaceto_smemoizationSpeed
to_sconversion (ops/sec)contains?repeated (ops/sec)empty?repeated (ops/sec)Allocations
34 version ranges parsed from test suite data.
to_sallocationscontains?allocationsempty?allocations