Commit 93aa273
authored
Improve performance of v1.NewHash (#2194)
* Improve performance of v1.NewHash
Previously, NewHash() made multiple unnecessary heap allocations that have been removed.
I've also added a simple benchmark test to measure the impact. Results below:
Before:
```
go test ./pkg/v1 -run XXX -bench BenchmarkNewHash
goos: darwin
goarch: arm64
pkg: github.com/google/go-containerregistry/pkg/v1
cpu: Apple M1 Pro
BenchmarkNewHash-10 8977393 123.1 ns/op 160 B/op 2 allocs/op
PASS
ok github.com/google/go-containerregistry/pkg/v1 1.711s
```
After:
```
$ go test ./pkg/v1 -run XXX -bench BenchmarkNewHash
goos: darwin
goarch: arm64
pkg: github.com/google/go-containerregistry/pkg/v1
cpu: Apple M1 Pro
BenchmarkNewHash-10 15214291 76.09 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/google/go-containerregistry/pkg/v1 1.805s
```
* add "Too many separators" cases to TestBadHashes1 parent 795787c commit 93aa273
2 files changed
+33
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
88 | | - | |
| 87 | + | |
| 88 | + | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
99 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
100 | 107 | | |
| 108 | + | |
101 | 109 | | |
102 | | - | |
103 | | - | |
| 110 | + | |
| 111 | + | |
104 | 112 | | |
105 | 113 | | |
106 | | - | |
107 | | - | |
| 114 | + | |
| 115 | + | |
108 | 116 | | |
109 | 117 | | |
110 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
| |||
113 | 118 | | |
114 | 119 | | |
115 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
0 commit comments