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

cmd/compile: Optimize three-way string comparisons #31187

Open
ashi009 opened this Issue Apr 1, 2019 · 3 comments

Comments

Projects
None yet
4 participants
@ashi009
Copy link

ashi009 commented Apr 1, 2019

As shown in strings.Compare's source code, three-way string comparisons can be optimized.

A few use cases are:

  • sorted slice merging
  • sorted slice intersection
  • sorted slice intersection detection

For the last use case my benchmark showed a over 10% improvement by using bytes.Compare instaed of strings.Compare.

@agnivade

This comment has been minimized.

Copy link
Member

agnivade commented Apr 1, 2019

@randall77

This comment has been minimized.

Copy link
Contributor

randall77 commented Apr 1, 2019

Currently we break string comparison ops into runtime calls during walk.
If we delayed that lowering until later in SSA, we could maybe detect the use of both s1 == s2 and s1 < s2 and use a single call in that case.

@randall77 randall77 added this to the Unplanned milestone Apr 1, 2019

@josharian

This comment has been minimized.

Copy link
Contributor

josharian commented Apr 1, 2019

This would be another possible use for an rtcall SSA pass: #24926

But it’d be better indeed to leave these unlowered until much later. Which would require making it reasonable to manipulate and insert calls in SSA. Which is yet another reason to move parameter and result handling into ssa ops instead of SP writes and reads. (I’m pretty sure I’ve written this paragraph a dozen times. I should just go do it.)

@josharian josharian changed the title Optimize three-way string comparisons cmd/compile: Optimize three-way string comparisons Apr 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.