-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/compile: intrinsify cmp.Compare on common types such as strings #71270
Comments
Even though this change may not seem hugely important or urgent, I would still argue for doing it sooner than later, before it's a "well known fact" that |
CC @golang/compiler |
Is adding a type switch to the beginning of
|
It actually makes it worse: the usual call boils down to |
CL 578835 removed the redundant calls to |
Change https://go.dev/cl/647235 mentions this issue: |
I have a separate set of CLs for removing the test+branch stuff, not quite ready to mail yet. |
Change https://go.dev/cl/648336 mentions this issue: |
Change https://go.dev/cl/648355 mentions this issue: |
#61725 optimized
strings.Compare
, which is great, but it did not optimizecmp.Compare[string]
, which is otherwise equivalent.This is leading to users learning that they should avoid
cmp.Compare[string]
for the sake of performance, even writing linters for it like https://github.com/tklauser/lintcomparestrings, which in my opinion is really unfortunate. For the same reason, I find changes like https://go-review.googlesource.com/c/go/+/642038 unfortunate and unnecessary.The compiler should be clever enough to optimize the generic
cmp.Compare
function just as well as specialized functions such asstrings.Compare
or any others that might exist for common comparable types such as integers. Then the developers don't have to remember facts about which one of them is faster.Personally, I also find it pretty nice to consistently use
cmp.Compare
. Needing to mix different compare functions in an expression for the sake of performance is a bit odd.The text was updated successfully, but these errors were encountered: