-
Notifications
You must be signed in to change notification settings - Fork 146
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
UUIDs: implement encoding methods, enhance testing and improve performance #347
base: dev
Are you sure you want to change the base?
Conversation
…mance This changeset implements these interfaces found in the encoding package: - MarshalBinary() (data []byte, err error) - UnmarshalBinary(data []byte) error - AppendBinary(b []byte) ([]byte, error) - MarshalText() (text []byte, err error) - UnmarshalText(text []byte) error - AppendText(b []byte) ([]byte, error) ParseUUID and uuid.String are now implemented in terms of these new methods. UnmarshalText and AppendText use algorithms inspired by the hex package. Also the UUID.String method has been optimized to avoid allocations by using unsafe.String. Finally the new UnmarshalText supports 128, 32 and 16 bit uuids. Additional tests were added to verify the new methods and some existing methods missing coverage. Benchmark results (using benchstat, 10 runs each): - `ParseUUID`: ~71.04% faster (p=0.000, n=10) - `UUID.String()`: ~81.26% faster (p=0.000, n=10) - `UUID.String()`: Memory allocations reduced by 100% (48 B/op to 0 B/op)
} | ||
|
||
// Using the reverseHexTable rebuild the UUID from the string s represented in bytes | ||
// This implementation is the inverse of MarshalText and reaches performance pairity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you mean the word "parity" here. 😸
component uint16 | ||
want UUID | ||
}{ | ||
// TODO: Add test cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO?
return nil | ||
} | ||
|
||
var reverseHexTable = [256]uint8{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps some explanation about the origin/functioning of this table?
This changeset implements these interfaces found in the encoding package:
- UnmarshalBinary(data []byte) error
- AppendBinary(b []byte) ([]byte, error)
- MarshalText() (text []byte, err error)
- UnmarshalText(text []byte) error
- AppendText(b []byte) ([]byte, error)
ParseUUID and uuid.String are now implemented in terms of these new methods. UnmarshalText and AppendText use algorithms inspired by the hex package. Also the UUID.String method has been optimized to avoid allocations by using unsafe.String. Finally the new UnmarshalText supports 128, 32 and 16 bit uuids.
Additional tests were added to verify the new methods and some existing methods missing coverage.
Benchmark results (using benchstat, 10 runs each):
-
ParseUUID
: ~71.04% faster (p=0.000, n=10)-
UUID.String()
: ~81.26% faster (p=0.000, n=10)-
UUID.String()
: Memory allocations reduced by 100% (48 B/op to 0 B/op)