Repository navigation
Conversation
_to_a assigned with = instead of ||=, so the VERSION string was split again on every call to major, minor, patch, and pre. Memoize it like the other cached helpers. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Signed-off-by: joe-sharp <joesharp13@gmail.com>
||= does not memoize nil, so pre re-ran _to_a on every call for versions without a pre-release suffix. Check defined?(@pre) instead. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Signed-off-by: joe-sharp <joesharp13@gmail.com>
This branch has not been deployed
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.
Two memoization gaps in
VersionGem::Api, fixed as separate commits._to_aused=instead of||=(⚡️ Memoize split version string in _to_a). TheVERSIONstring was split again on every call tomajor,minor,patch, andpre.prenever cachednil(⚡️ Cache nil pre-release in pre).||=treatsnilas unset, so a version with no pre-release re-ran_to_aon everyprecall. The fix checksdefined?(@pre)instead.Each commit adds a spec that fails without its fix, a Keep a Changelog entry under
Unreleased→Fixed, and a DCO sign-off.Summary
Cold lookups are about 30% faster, and warm
preon a version with no pre-release is about 9× faster. The split count drops from 4–6 per cold lookup to 1.Benchmark
Ruby 4.0.9, 20,000 iterations per run, median of 7 runs.
splits/opcountsString#splitcalls per operation. Three interleaved runs ofmainand three of this branch, rerun on the same machine:1.2.3(major, minor, patch, pre, to_h, to_a)1.2.3.pre-783012.34.56pre,1.2.3(no pre-release)pre,1.2.3.pre-78majorto_a(Epoch)Takeaways
preon a version with no pre-release is about 9× faster (≈0.83 µs → ≈0.08 µs). This is the fix 2 win.Reproducing
The benchmark script is not in the repo. It loads
lib/directly, prepends a counter ontoString#split, and timesITERcalls of each scenario. Run it with:Run it against a checkout of
main(git archive main lib) and against this branch to compare.Testing
bundle exec rspec: 32 examples, 0 failures.bundle exec rubocop lib/version_gem/api.rb spec/version_gem/api_spec.rb: no offenses.bundle exec kettle-testwas not run, becausemiseis not installed in the environment used for this change. The full RSpec suite was run directly instead.🤖 Generated with Claude Code