Repository navigation
Compare IntDot versions without splitting into slices - #67
Conversation
compareIntDot split both versions with strings.Split before comparing, which cost two allocations per call. It now walks both versions one dot-separated component at a time, comparing the same components with cmpNumStr, and a missing component still compares as "". intdot_reference_test.go keeps the previous implementation as a reference for parity tests over the shared corpus, IntDot edge cases and the vers-spec fixtures, plus a fuzz target. IntDot joins TestEcosystemComparatorsDoNotAllocate and BenchmarkCompareWithScheme. Co-authored-by: Claude <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Refs #31, the IntDot item.
compareIntDotcalledstrings.Spliton both versions before comparing them (two allocations per call). It now walks both versions in lockstep, one dot-separated component at a time, and passes the same components tocmpNumStr. A side that runs out of components keeps yielding"", which is how a missing component compared before.intDotPrefixis unchanged.go test -bench 'BenchmarkCompareWithScheme/IntDot' -benchmem, Go 1.26.7, linux/amd64, before and after run alternately (3 rounds of-count 3, so 9 runs each) on a slow, busy 2-core machine. Read the ratio, not the absolute numbers. The time gain on the uneven pair is within the noise here; the allocations are the steady part:1.2.3vs1.2.41.2.3.4.5.6.7.8.9vs1.2.3.4.5.6.7.8Both rows are new in
BenchmarkCompareWithScheme.Coverage follows the ALPM/Conan/Gentoo rewrite:
intdot_reference_test.gois a mechanically renamed copy of the oldintDotPrefixandcompareIntDot.TestCompareIntDotMatchesReferencecovers every ordered pair of the shared parity corpus plus IntDot forms: leading zeros, components past the 64-bit range, empty components from leading, repeated and trailing dots, long and uneven component counts, and the characters that end the numeric prefix (letters,-,,, spaces, NUL, non-ASCII digits).TestCompareIntDotMatchesReferenceOnFixturescovers every pair from the conformance fixtures.FuzzCompareIntDotMatchesReferenceran 60 s here (219k execs), with no difference.TestEcosystemComparatorsDoNotAllocatewith three pairs: equal length, uneven length, and a version with a suffix after the numeric prefix. All three fail on main with 2 allocations.Mutations, one at a time, in a separate worktree: the loop stopping at the shorter side, no prefix trim on one side, a text comparison instead of
cmpNumStr, one side reading the other side's index, the last component cut short, a past-the-end call returning a character, and a past-the-end index that never moves on. All 7 turn a test red. Two of them loop forever, so they fail on the 60 s test timeout.go test ./...ok,golangci-lint run0 issues,go vetok, gofmt clean. Exported APIs and the scheme ordering are unchanged.Summary by CodeRabbit