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

A new performance check: prefer operator comparisons to strings.Compare #1167

Closed
go101 opened this issue Dec 17, 2021 · 5 comments
Closed

A new performance check: prefer operator comparisons to strings.Compare #1167

go101 opened this issue Dec 17, 2021 · 5 comments
Labels
checker request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@go101
Copy link

go101 commented Dec 17, 2021

The current implementation of the strings.Compare function is not efficient, in a some deliberate way.
refs:

At least, for non-three-way comparisons, using operators to compare strings is always faster than using the strings.Compare function.

@peakle
Copy link
Contributor

peakle commented Jan 15, 2022

@go101
you can try to open pr to https://github.com/quasilyte/go-perfguard with optimization rule like:
m.Match(`strings.Compare($_, $_)`).Report(`strings.Compare in hot path`)

contribution guide: https://github.com/quasilyte/go-perfguard/blob/master/_docs/CONTRIBUTING.md

@quasilyte
Copy link
Member

quasilyte commented Jan 15, 2022

I would add them to go-critic though.
go-critic is something that is more useful for most users.
perfguard is an experiment that has ~0 integrations.

I think that checkers/rules is a good place for these.

@quasilyte
Copy link
Member

By the way.

@go101 thank you for your books. ❤️

@peakle
Copy link
Contributor

peakle commented Feb 10, 2022

@quasilyte can be closed as i see

@quasilyte
Copy link
Member

I think that we haven't implemented all of the suggested patterns.
Some of them can't be expressed in ruleguard rules beautifully, so maybe someone would like to create a separate checker for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checker request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants