Commit a85a526
authored
Improve performance of FromBytesOrNil (#206)
This pulls code from FromBytes and UnmarshalBinary into FromBytesOrNil
which reduces the cost of creating a UUID from a byte slice. It also
removes an allocation when the UUID is invalid as it no longer generates
an error which is discarded. One downside of this approach is that it
duplicates the logic from UnmarshalBinary.
```
goos: linux
goarch: amd64
pkg: github.com/gofrs/uuid/v5
cpu: AMD Ryzen 9 5950X 16-Core Processor
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
FromBytesOrNil/valid-32 3.814n ± 0% 1.118n ± 1% -70.69% (n=100)
FromBytesOrNil/empty-32 135.3500n ± 0% 0.6514n ± 1% -99.52% (n=100)
geomean 22.72n 0.8534n -96.24%
│ old.txt │ new.txt │
│ B/op │ B/op vs base │
FromBytesOrNil/valid-32 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=100) ¹
FromBytesOrNil/empty-32 96.00 ± 0% 0.00 ± 0% -100.00% (n=100)
│ old.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
FromBytesOrNil/valid-32 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=100) ¹
FromBytesOrNil/empty-32 2.000 ± 0% 0.000 ± 0% -100.00% (n=100)
```1 parent 1404e37 commit a85a526
2 files changed
+23
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
41 | 46 | | |
42 | 47 | | |
43 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
345 | 361 | | |
346 | 362 | | |
347 | 363 | | |
| |||
0 commit comments