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

// Using the reverseHexTable rebuild the UUID from the string s represented in bytes
// This implementation is the inverse of MarshalText and reaches performance pairity
Copy link
Member

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.
Copy link
Member

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{
Copy link
Member

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?

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.

2 participants