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

UUIDs: implement encoding methods, enhance testing and improve performance #347

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

onshorechet
Copy link

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)

…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)
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