Optimize version comparison hot paths - #30
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Optimizes version parsing and comparison hot paths by replacing regex/split-based logic with allocation-free scanners across SemVer, RubyGems, and NuGet, and adds parity tests/benchmarks to validate the new scanners.
Changes:
- Replaced SemVer matching/comparison and NuGet prerelease/numeric parsing with scanner-based, low-allocation implementations.
- Replaced VERS URI and constraint operator regex parsing with prefix/index scans.
- Added property-based parity tests and additional benchmarks; tightened interval containment edge coverage.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| version.go | Switches SemVer detection/parsing in ParseVersion and SemVer fast path in CompareVersions to scanner-based parsing. |
| schemes.go | Implements allocation-free SemVer scanner/prerelease comparison and RubyGems segment scanning (replacing regex/split). |
| schemes_test.go | Adds randomized parity tests ensuring scanner behavior matches the legacy regex/regexp behavior; adds NuGet edge cases. |
| pypi.go | Reuses qualifierPre constant in PEP 440 pre-tag mapping. |
| parser.go | Replaces vers: URI regex parsing with prefix + slash scan and adds newline guard for constraints. |
| parser_test.go | Adds test coverage for missing separator and newline-in-constraints VERS URI cases. |
| interval.go | Removes redundant early returns in containsCmp and relies on bound checks for correctness. |
| interval_test.go | Adds coverage for equal exclusive bounds containment behavior. |
| ecosystem_extra.go | Uses qualifierPre constant for Gentoo suffix rank handling. |
| constraint.go | Replaces operator regex with a small scanner (constraintOperator). |
| bench_test.go | Adds benchmarks for scheme comparison, constraint parsing, cached parsing, validation, and highest-satisfying selection. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
7 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.
Replace regexp- and split-based SemVer, RubyGems, and NuGet comparison with allocation-free scanners. Avoid redundant interval comparisons and regexp parsing for VERS URIs and constraints.
Add benchmarks for scheme comparison, parsing, validation, and highest-satisfying selection, plus randomized parity coverage for scanner behavior.