Skip to content

cmd/compile: intrinsify strings.Compare #61725

@dsnet

Description

@dsnet

A comment by @rsc in strings.Compare says:

This function does NOT call the runtime cmpstring function,
because we do not want to provide any performance justification for
using strings.Compare. Basically no one should use strings.Compare.
As the comment above says, it is here only for symmetry with package bytes.
If performance is important, the compiler should be changed to recognize
the pattern so that all code doing three-way comparisons, not just code
using strings.Compare, can benefit.

I'm not sure this comment has aged well with the recent change to slices.SortFunc,
where it now takes in an func(T, T) int instead of func(T, T) bool.
This means that the utility of strings.Compare suddenly shot up.

We should either intrinsify strings.Compare as runtime.cmpstring OR (even better) recognize this pattern.
That way, cmp.Compare on string types will benefit as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsFixThe path to resolution is known, but the work has not been done.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions