Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address some linting issues, and small refactor, performance optimizations #103

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

thaJeztah
Copy link
Member

address some linting issues

  • rename "digester" vars that shadowed package-level digester type
  • rename "hexdigestbytes" to be properly camelCase
  • update test to use "errors.Is()" instead of straight compare

testdigest: fix package GoDoc to be in the right format

remove import aliases

RegisterAlgorithm: skip regex if not needed

No need to validate the format if we previously accepted it to be
registered.

use errors.New() for errors that don't need formatting

digestset: report allocations in benchmarks

Just for convenience ':-)

Before:

pkg: github.com/opencontainers/go-digest/digestset
BenchmarkAdd10-10              183613      6368 ns/op
BenchmarkAdd100-10              15739     75741 ns/op
BenchmarkAdd1000-10              1430    831884 ns/op
BenchmarkRemove10-10           169999      6984 ns/op
BenchmarkRemove100-10           15312     78299 ns/op
BenchmarkRemove1000-10           1470    815144 ns/op
BenchmarkLookup10-10         27067897        43.69 ns/op
BenchmarkLookup100-10        17203653        69.17 ns/op
BenchmarkLookup1000-10       13043708        96.32 ns/op
BenchmarkShortCode10-10       3574094       334.5 ns/op
BenchmarkShortCode100-10       320438      3782 ns/op
BenchmarkShortCode1000-10       29110     41460 ns/op

After:

pkg: github.com/opencontainers/go-digest/digestset
BenchmarkAdd10
BenchmarkAdd10-10              176776      6400 ns/op         608 B/op      12 allocs/op
BenchmarkAdd100-10              15267     76016 ns/op        5746 B/op     102 allocs/op
BenchmarkAdd1000-10              1426    833977 ns/op       56267 B/op    1002 allocs/op
BenchmarkRemove10-10           169448      7043 ns/op         128 B/op       2 allocs/op
BenchmarkRemove100-10           15249     78730 ns/op         944 B/op       2 allocs/op
BenchmarkRemove1000-10           1444    819247 ns/op        8240 B/op       2 allocs/op
BenchmarkLookup10-10         27042379        45.68 ns/op        0 B/op       0 allocs/op
BenchmarkLookup100-10        17098725        69.72 ns/op        0 B/op       0 allocs/op
BenchmarkLookup1000-10       12769602        92.97 ns/op        0 B/op       0 allocs/op
BenchmarkShortCode10-10       3551202       332.1 ns/op	      630 B/op       2 allocs/op
BenchmarkShortCode100-10       313929      3805 ns/op        5449 B/op       4 allocs/op
BenchmarkShortCode1000-10       28963     41373 ns/op       81992 B/op       3 allocs/op

remove unneeded fmt.Sprintf and indirections

Remove fmt.Sprintf and use string-concatenation instead to reduce
some allocations.

Before / After:

BenchmarkNewDigestFromEncoded-10     8474174   128.4 ns/op   112 B/op  3 allocs/op
BenchmarkNewDigestFromEncoded-10    37912695    31.55 ns/op   80 B/op  1 allocs/op

BenchmarkNewDigestFromBytes-10       5087299    237.2 ns/op	 200 B/op  5 allocs/op
BenchmarkNewDigestFromBytes-10       8416543    146.8 ns/op	 168 B/op  3 allocs/op

- rename "digester" vars that shadowed package-level digester type
- rename "hexdigestbytes" to be properly camelCase
- use "errors.Is()" instead of straight comparing errors

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
No need to validate the format if we previously accepted it to be
registered.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Just for convenience ':-)

Before:

    pkg: github.com/opencontainers/go-digest/digestset
    BenchmarkAdd10-10              183613      6368 ns/op
    BenchmarkAdd100-10              15739     75741 ns/op
    BenchmarkAdd1000-10              1430    831884 ns/op
    BenchmarkRemove10-10           169999      6984 ns/op
    BenchmarkRemove100-10           15312     78299 ns/op
    BenchmarkRemove1000-10           1470    815144 ns/op
    BenchmarkLookup10-10         27067897        43.69 ns/op
    BenchmarkLookup100-10        17203653        69.17 ns/op
    BenchmarkLookup1000-10       13043708        96.32 ns/op
    BenchmarkShortCode10-10       3574094       334.5 ns/op
    BenchmarkShortCode100-10       320438      3782 ns/op
    BenchmarkShortCode1000-10       29110     41460 ns/op

After:

    pkg: github.com/opencontainers/go-digest/digestset
    BenchmarkAdd10
    BenchmarkAdd10-10              176776      6400 ns/op         608 B/op      12 allocs/op
    BenchmarkAdd100-10              15267     76016 ns/op        5746 B/op     102 allocs/op
    BenchmarkAdd1000-10              1426    833977 ns/op       56267 B/op    1002 allocs/op
    BenchmarkRemove10-10           169448      7043 ns/op         128 B/op       2 allocs/op
    BenchmarkRemove100-10           15249     78730 ns/op         944 B/op       2 allocs/op
    BenchmarkRemove1000-10           1444    819247 ns/op        8240 B/op       2 allocs/op
    BenchmarkLookup10-10         27042379        45.68 ns/op        0 B/op       0 allocs/op
    BenchmarkLookup100-10        17098725        69.72 ns/op        0 B/op       0 allocs/op
    BenchmarkLookup1000-10       12769602        92.97 ns/op        0 B/op       0 allocs/op
    BenchmarkShortCode10-10       3551202       332.1 ns/op	      630 B/op       2 allocs/op
    BenchmarkShortCode100-10       313929      3805 ns/op        5449 B/op       4 allocs/op
    BenchmarkShortCode1000-10       28963     41373 ns/op       81992 B/op       3 allocs/op

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Remove fmt.Sprintf and use string-concatenation instead to reduce
some allocations.

Before / After:

    BenchmarkNewDigestFromEncoded-10     8474174   128.4 ns/op   112 B/op  3 allocs/op
    BenchmarkNewDigestFromEncoded-10    37912695    31.55 ns/op   80 B/op  1 allocs/op

    BenchmarkNewDigestFromBytes-10       5087299    237.2 ns/op	 200 B/op  5 allocs/op
    BenchmarkNewDigestFromBytes-10       8416543    146.8 ns/op	 168 B/op  3 allocs/op

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