-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: a string | []byte generic constraint isn't a zero-cost abstraction #73417
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
Comments
Interestingly, substituting
|
@thepudds Thanks! Yes, the absence of inlining in my implementation likely explains the performance gap. |
Isn't this #68236? At least reading it it sounds like generic functions "should" be slower today? |
🤔 Although the lack of inlining due to |
Go version
go version go1.24.2 darwin/amd64
Output of
go env
in your module/workspace:What did you do?
(The complete code is available in this Gist.)
I eliminated the code duplication between
utf8.DecodeRune
andutf8.DecodeRuneInString
by delegating to a generic function with astring | []byte
type constraint:I also wrote some benchmarks:
What did you see happen?
Quite a large performance gap between Go 1.24.2 and this implementation:
What did you expect to see?
I expected to observe no such performance degradation between Go 1.24.2 and this implementation. It is not only disappointing but difficult to explain; see this thread on Gophers Slack. Such a generic constraint, if it were "free", would unlock much code deduplication in the standard library (see also net/textproto.TrimString and net/textproto.TrimBytes) and beyond.
Related: #56948
The text was updated successfully, but these errors were encountered: