Skip to content

specs-go: remove x/mod semver dependency - #333

Draft
thaJeztah wants to merge 3 commits into
cncf-tags:mainfrom
thaJeztah:specs_nodeps
Draft

specs-go: remove x/mod semver dependency#333
thaJeztah wants to merge 3 commits into
cncf-tags:mainfrom
thaJeztah:specs_nodeps

Conversation

@thaJeztah

Copy link
Copy Markdown
Contributor

specs-go: remove x/mod semver dependency

CDI spec versions are a small, fixed set, so using
golang.org/x/mod/semver just to compare them is unnecessary.

Keep the versions in order instead and use that ordering for validation and
minimum-version checks. This also keeps support for versions with or without a
leading v.

As a side effect, ValidateVersion gets noticeably faster for valid versions
in local benchmarks, with no change in allocations.

I wrote a quick benchmark, but probably not worth to keep (so I can drop that commit);

pkg: tags.cncf.io/container-device-interface/specs-go
                          │ before.txt  │              after.txt              │
                          │   sec/op    │   sec/op     vs base                │
ValidateVersion/first-2     276.9n ± 1%   155.8n ± 1%  -43.71% (p=0.000 n=10)
ValidateVersion/middle-2    279.4n ± 1%   171.1n ± 1%  -38.77% (p=0.000 n=10)
ValidateVersion/last-2      354.9n ± 0%   259.9n ± 1%  -26.78% (p=0.000 n=10)
ValidateVersion/invalid-2   131.9n ± 1%   137.9n ± 1%   +4.55% (p=0.000 n=10)
geomean                     245.3n        175.8n       -28.33%

                          │ before.txt │              after.txt              │
                          │    B/op    │    B/op     vs base                 │
ValidateVersion/first-2     592.0 ± 0%   592.0 ± 0%       ~ (p=1.000 n=10) ¹
ValidateVersion/middle-2    592.0 ± 0%   592.0 ± 0%       ~ (p=1.000 n=10) ¹
ValidateVersion/last-2      672.0 ± 0%   672.0 ± 0%       ~ (p=1.000 n=10) ¹
ValidateVersion/invalid-2   280.0 ± 0%   280.0 ± 0%       ~ (p=1.000 n=10) ¹
geomean                     506.7        506.7       +0.00%
¹ all samples are equal

                          │ before.txt │              after.txt              │
                          │ allocs/op  │ allocs/op   vs base                 │
ValidateVersion/first-2     5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
ValidateVersion/middle-2    5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
ValidateVersion/last-2      8.000 ± 0%   8.000 ± 0%       ~ (p=1.000 n=10) ¹
ValidateVersion/invalid-2   4.000 ± 0%   4.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                     5.318        5.318       +0.00%
¹ all samples are equal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
CDI spec versions are a small, fixed set, so using
`golang.org/x/mod/semver` just to compare them is unnecessary.

Keep the versions in order instead and use that ordering for validation and
minimum-version checks. This also keeps support for versions with or without a
leading `v`.

As a side effect, `ValidateVersion` gets noticeably faster for valid versions
in local benchmarks, with no change in allocations.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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.

1 participant