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

server/storage/schema: prefer equal to compare for equality comparisons #15915

Merged
merged 1 commit into from
May 18, 2023

Conversation

hexfusion
Copy link
Contributor

Benchmarks show bytes.Equal is much faster than bytes.Compare[1] for equality comparisons and preferred per the example in docs[2].

[1] https://www.sobyte.net/post/2022-01/go-bytes-compare-equal/
[2] https://pkg.go.dev/bytes#Compare

Signed-off-by: Sam Batschelet <sbatschelet@gmail.com>
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks @hexfusion

Copy link
Member

@jmhbnz jmhbnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Though is there any context on how much of a difference this will make for etcd? The linked benchmarks are in nanoseconds per operation, I'm wondering if there is expected to be a more pronounced impact for etcd?

If not it would probably not be a priority to review any other code using bytes.Compare though at first glance this looks like it might be the only instance where we do a straight ==.

Copy link
Member

@fuweid fuweid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ahrtr
Copy link
Member

ahrtr commented May 17, 2023

where we do a straight ==.

FYI. Slice, map, and function types are not comparable in golang.

@ahrtr ahrtr merged commit 19ec574 into etcd-io:main May 18, 2023
@hexfusion hexfusion deleted the bytes branch May 18, 2023 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants