Skip to content

Compare PyPI versions without allocating component slices - #68

Merged
andrew merged 2 commits into
git-pkgs:mainfrom
akzarma:perf/pypi-version-comparison
Dec 1, 2026
Merged

andrew merged 2 commits into
git-pkgs:mainfrom
akzarma:perf/pypi-version-comparison

Conversation

@akzarma

@akzarma akzarma commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Addresses the PyPI item in #31. The other comparators are unchanged.

For ASCII PEP 440 versions, the parser keeps the release and local labels as views into the input instead of allocating regexp captures and component lists. Comparisons walk the components in place. Non-ASCII inputs still use the original regexp to preserve its Unicode case folding (e.g. a Kelvin sign in a local label). Invalid versions still fall back to generic comparison.

Median of five runs of BenchmarkPyPIComparison on darwin/arm64, Apple M1 Pro, Go 1.26.7, GOMAXPROCS=2, 200 ms per sample:

Pair ns/op, before → after B/op allocs/op
Release 1,495 → 143 801 → 0 6 → 0
Prerelease with epoch 1,446 → 202 801 → 0 6 → 0
Local labels with mixed case and separators 2,265 → 436 1,042 → 0 11 → 0

The allocation test failed on the unmodified base at 6/6/11 allocations and passes here. Added differential ordering tests against the regexp/split implementation, including invalid versions, Unicode and 1,050 suffix combinations. With the upstream fixtures checked out, go build ./..., go vet ./..., go test -race ./..., a 20-second differential fuzz run, and golangci-lint run ./... passed locally. Other platforms were not run locally.

AI assistance: OpenAI Codex (GPT-6.2 Astra) implemented this change and its tests, ran the checks and benchmarks, and drafted this description.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Python package version parsing and comparison, including release numbers, prerelease and post-release markers, development versions, and local labels.
    • Corrected upper-bound handling for compatible-release and prefix version ranges.
    • Improved consistency when comparing versions with or without local labels.
  • Tests
    • Added broader checks for version comparison behavior, including edge cases and consistency with reference results.

Scan ASCII PEP 440 components and walk release and local labels in place. Keep the regexp path for Unicode case-folding compatibility.
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

PEP 440 parsing and comparison now use string-backed release and local-version components. Release bounds, range equality, and version formatting use the updated representation. New tests check parser and comparison parity, allocation behavior, and benchmarks.

Changes: PEP 440 parsing and version handling

Layer / File(s) Summary
String-backed parsing and comparison
pypi.go, schemes.go, pypi_comparison_test.go
The PEP 440 parser stores release and local versions as strings and uses a byte-oriented parser for ASCII input. Comparison uses dot-number release comparison and compares local labels directly. Tests check parity with a regular-expression reference, fuzz cases, allocations, and benchmarks.
Release bounds and range equality
pypi.go, parser.go, range.go
Compatible and prefix upper bounds use release-string incrementing. PEP 440 range equality compares release strings and clears local labels when they are ignored.
PEP 440 version formatting
normalization.go
Formatting processes release and local components from encoded strings, trims numeric leading zeros, and lowercases nonnumeric local components.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Possibly related issues

  • Issue 31: The PR addresses the PyPI parsing and comparison optimization, including differential tests and benchmarks. The issue’s other items are not covered by this PR.

Suggested reviewers: andrew

Merge Risk: Minimal · up to 41845

This change speeds up PyPI version comparison and avoids allocations, while keeping the regexp path for non-ASCII input and the generic fallback for invalid versions. Parser parity checks found no behavioral difference, so no merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Compare PyPI versions without allocating component slices" matches the main change. The changeset replaces slice-based PEP 440 release and local-label handling with string views and in-plac…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Compare PyPI versions without allocating component slices" matches the main change. The changeset replaces slice-based PEP 440 release and local-label handling with string views and in-place comparison (compareDotNumbers, byte-oriented ASCII parser). The PR objectives state the same goal: avoid regexp captures and component-list allocations for PyPI comparison. The added allocation tests and benchmarks also support the title.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 29fafe23-3f91-4113-9dfb-4b97099c50ed
Commits

Reviewing files that changed from the base of the PR and between d043dac and 41845d5.

Files selected for processing: 6

  • normalization.go
  • parser.go
  • pypi.go
  • pypi_comparison_test.go
  • range.go
  • schemes.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@andrew
andrew merged commit 76f6e73 into git-pkgs:main Dec 1, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants