Repository navigation
Compare APK versions without building token slices - #66
Merged
Merged
Conversation
compareAPK parsed each side into a []apkToken before comparing, which cost two allocations per comparison (four once a version has more than six tokens). It now walks both versions in lockstep with apkScanner, which yields one token at a time; validAPKVersion and apkVersionIsPrerelease use the same scanner. The pre-change implementation is kept as apk_reference_test.go, and the new comparator and both classifiers are checked against it on the shared corpus plus APK forms, apk-tools' apk_version.data and the conformance fixtures, with a fuzz target for the comparator. APK joins TestEcosystemComparatorsDoNotAllocate. Refs git-pkgs#31 Co-authored-by: Claude <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed.
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. |
7 of 8 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.
Refs #31, the APK item.
compareAPKbuilt a[]apkTokenfor each side (apk.go:41-42) before comparing. It now walks both versions in lockstep with a smallapkScannerthat yields one token at a time, using the same tokenizer rules in the same order.validAPKVersionandapkVersionIsPrereleaseuse the same scanner, soparseAPKVersionandapkTokenTypeare gone.apkVersionIsPrereleaselost its own invalid-token check, because the scanner ends at the first invalid token. Only a suffix before that token can decide, which is how the old loop behaved as well.go test -bench 'BenchmarkCompareWithScheme/APK$' -benchmem -count 5, Go 1.26.7, linux/amd64 (a slow 2-core machine, so read the ratio, not the absolute numbers):A version with more than six tokens outgrew the slice's initial capacity, so
1.2.3a_p1~abc-r2against1.2.3a_p1~abd-r1allocated 4 times on main.Coverage, following the ALPM/Conan/Gentoo rewrite:
apk_reference_test.gois a mechanically renamed copy of the oldcompareAPK/parseAPKVersion/apkTokenType.TestCompareAPKMatchesReferencecovers every ordered pair of the shared parity corpus plus APK forms: each suffix with and without a number, commit hashes, revisions, letters, leading zeros, surrounding whitespace, overflowing numbers, and each way a version turns invalid part-way.TestCompareAPKMatchesReferenceOnDatacovers every pair from apk-tools'apk_version.dataand the conformance fixtures.TestAPKClassifiersMatchReferencechecksvalidAPKVersionandapkVersionIsPrereleaseagainst the reference on the same inputs.FuzzCompareAPKMatchesReferenceran 90 s here (275k execs), with no difference.TestEcosystemComparatorsDoNotAllocatewith three pairs: a suffix, hash plus revision, and an invalid suffix. All three fail on main, with 2, 4 and 2 allocations.TestAPKScannerEndsAfterInvalidTokenpins the one scanner property the comparator relies on but can't observe.Mutations, one at a time, in a separate worktree: no
TrimSpace, the end-of-input check off by one,validAPKVersionignoring invalid tokens, the prerelease-suffix tie flipped, and the scanner continuing after an invalid token. All 5 turn a test red.go test ./...ok,golangci-lint run0 issues, gofmt clean. Exported APIs and the scheme ordering are unchanged. The branch is rebased on 2b66c01, where the only change since 70710c0 is the setup-go bump. Tests, lint and a bench rerun there (384-438 ns, 0 B, 0 allocs) give the same results.