-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
Report slow string convertions using fmt #1036
Comments
Similar to go-critic/go-critic#873. |
The problem with checks like these is that performance doesn't always matter. In a lot of contexts, consistency with surrounding code is more important. |
Maybe, but I think this is an easy win in performance without loosing readability. I would almost argue that it, if anything, actually improves readability of the code in question. With using |
I frequently see If staticcheck does S1025 - Don’t use fmt.Sprintf("%s", x) unnecessarily , it should do this too. |
I disagree. I see two differences between that and S1025:
|
Sounds like this could be an |
Are we talking about the same thing? The change from from |
I don't consider one to be simpler than the other. Faster, maybe, but not simpler. Especially in code that is concerned with output, not computation, using fmt seems much more natural to me. |
I'd suggest adding another one to the list here. I've seen a lot of usages of |
Covered by golangci/golangci-lint#3714 |
I think it would be very good if staticcheck could flag cases where people are using
fmt
for just simply converting to and from strings. It was found in my PR for fyne-io/fyne (fyne-io/fyne#2142 (comment)) that thestrconv
package generally is twice as fast as thefmt
package for converting to and from strings. While it is very easy and simple to do so, I think it is a poor decision most of the time.Below are a few examples of what I would suggest flagging:
All these cases can quite easily be changed to using
strconv
for pretty big performance improvements.The text was updated successfully, but these errors were encountered: