Commit 72666c8
committed
Some performance optimizations
* Avoid creating new `reflect.Value`s for common int, uint and bool types.
* Use `io.WriteString` to write strings. This uses `io.StringWriter` if it exists, which is implemented by e.g. github.com/cespare/xxhash.
Compared to master:
```
goos: darwin
goarch: arm64
pkg: github.com/gohugoio/hashstructure
cpu: Apple M1 Pro
│ cmpmaster.bench │ perf-20250205.bench │
│ sec/op │ sec/op vs base │
Map-10 1.963µ ± 17% 1.291µ ± 13% -34.23% (p=0.002 n=6)
String/default-10 80.90n ± 1% 84.41n ± 0% +4.34% (p=0.002 n=6)
String/xxhash-10 54.83n ± 1% 40.12n ± 0% -26.82% (p=0.002 n=6)
geomean 205.7n 163.5n -20.52%
│ cmpmaster.bench │ perf-20250205.bench │
│ B/op │ B/op vs base │
Map-10 573.5 ± 22% 382.0 ± 13% -33.39% (p=0.002 n=6)
String/default-10 56.00 ± 0% 56.00 ± 0% ~ (p=1.000 n=6) ¹
String/xxhash-10 48.00 ± 0% 16.00 ± 0% -66.67% (p=0.002 n=6)
geomean 115.5 69.95 -39.45%
¹ all samples are equal
│ cmpmaster.bench │ perf-20250205.bench │
│ allocs/op │ allocs/op vs base │
Map-10 57.50 ± 20% 37.00 ± 14% -35.65% (p=0.002 n=6)
String/default-10 3.000 ± 0% 3.000 ± 0% ~ (p=1.000 n=6) ¹
String/xxhash-10 2.000 ± 0% 1.000 ± 0% -50.00% (p=0.002 n=6)
geomean 7.014 4.806 -31.48%
```
Compared to `mitchellh/hashstructure`:
```
goos: darwin
goarch: arm64
pkg: github.com/gohugoio/hashstructure
cpu: Apple M1 Pro
│ cmpfork.bench │ perf-20250205.bench │
│ sec/op │ sec/op vs base │
Map-10 2.789µ ± 6% 1.292µ ± 41% -53.69% (p=0.002 n=6)
String/default-10 83.45n ± 0% 87.36n ± 1% +4.69% (p=0.002 n=6)
String/xxhash-10 56.19n ± 0% 41.59n ± 1% -25.98% (p=0.002 n=6)
geomean 235.6n 167.4n -28.94%
│ cmpfork.bench │ perf-20250205.bench │
│ B/op │ B/op vs base │
Map-10 1461.0 ± 6% 393.0 ± 27% -73.10% (p=0.002 n=6)
String/default-10 56.00 ± 0% 56.00 ± 0% ~ (p=1.000 n=6) ¹
String/xxhash-10 48.00 ± 0% 16.00 ± 0% -66.67% (p=0.002 n=6)
geomean 157.8 70.62 -55.24%
¹ all samples are equal
│ cmpfork.bench │ perf-20250205.bench │
│ allocs/op │ allocs/op vs base │
Map-10 87.50 ± 9% 36.50 ± 40% -58.29% (p=0.002 n=6)
String/default-10 3.000 ± 0% 3.000 ± 0% ~ (p=1.000 n=6) ¹
String/xxhash-10 2.000 ± 0% 1.000 ± 0% -50.00% (p=0.002 n=6)
geomean 8.067 4.784 -40.70%
````1 parent 57e8e3b commit 72666c8
4 files changed
+58
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
125 | 133 | | |
126 | 134 | | |
127 | 135 | | |
| |||
152 | 160 | | |
153 | 161 | | |
154 | 162 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
166 | 167 | | |
167 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
168 | 181 | | |
169 | 182 | | |
170 | 183 | | |
171 | 184 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
178 | 191 | | |
179 | 192 | | |
180 | 193 | | |
| |||
394 | 407 | | |
395 | 408 | | |
396 | 409 | | |
397 | | - | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
398 | 414 | | |
399 | 415 | | |
400 | 416 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
727 | 729 | | |
728 | 730 | | |
729 | 731 | | |
| 732 | + | |
730 | 733 | | |
731 | 734 | | |
732 | 735 | | |
| |||
846 | 849 | | |
847 | 850 | | |
848 | 851 | | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
849 | 868 | | |
850 | 869 | | |
851 | 870 | | |
| |||
0 commit comments