Skip to content

cmd/compile: intrinsify cmp.Compare on common types such as strings #71270

@mvdan

Description

@mvdan

#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions