-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
#61725 optimized strings.Compare, which is great, but it did not optimize cmp.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 as strings.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.