-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
optimizations #63
optimizations #63
Conversation
func hashedUUID(space uuid.UUID, data string) (u uuid.UUID) { | ||
h := sha1.New() | ||
h.Write(space[:]) //nolint:errcheck | ||
h.Write(unsafe.Slice(unsafe.StringData(data), len(data))) //nolint:errcheck |
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 noticed that in google/uuid#181, you're not using unsafe
?
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.
yes, in that PR signature accepts data []byte
.
unsafe here is used to read input string as a byte slice without allocating additional objects.
So if that PR is merged and released, it could then be integrated here as:
u = uuid.NewSHA1(uuid.NameSpaceDNS, unsafe.Slice(unsafe.StringData(data), len(data)))
instead of
u = uuid.NewSHA1(uuid.NameSpaceDNS, []byte(data))
as this []byte
conversion sometimes adds an additional allocation.
Again, thanks 🙂 |
Key changes:
hashedUUID
function to reduce allocation inNewWithNamespace
, as google'suuid.NewSHA1
makes 4 unnecessary allocationsBenchamarks: