You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would expect the compiler to transform the calls to strings.Join with a finite number of elements into simple string concatenations. The reason is that these calls might be used on hot-paths for code, for example: aws/aws-sdk-go#729
The results might be small, see below for my machine, but any speed improvement is a good one imho
go test -bench=.
BenchmarkStringsJoin-8 10000000 140 ns/op
BenchmarkStringsConcat-8 20000000 92.6 ns/op
PASS
ok some/package 3.505s
go test -bench=. -benchmem
BenchmarkStringsJoin-8 10000000 136 ns/op 128 B/op 2 allocs/op
BenchmarkStringsConcat-8 20000000 96.6 ns/op 64 B/op 1 allocs/op
PASS
ok some/package 3.565s
Thank you.
The text was updated successfully, but these errors were encountered:
Could be done. The simple fix is to make strings.Join work similarly to runtime.concatstrings, in particular to use rawstring instead of doing the concat in a byte slice and then converting to a string.
A bigger change would be to do semantic inlining of strings.Join in the compiler.
A bigger change would be to do semantic inlining of strings.Join in the compiler.
That seems too big. Most of the standard library should not be special. Maybe parts of sync, runtime, and time can be recognized by the compiler, but not high-level packages likes "strings".
FWIW, 3ddc9ad was already submitted to optimize the common cases of strings.Join.
@randall77, I'm of the opinion that this bug should be closed and the compiler shouldn't special case things in the standard library, at least not in regular (unprivileged) packages like "strings".
go version
)?go version go1.7beta2 linux/amd64
go env
)?GOHOSTARCH="amd64"
GOHOSTOS="linux"
Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Given the following example: https://play.golang.org/p/a_ow6e7II7
I would expect the compiler to transform the calls to
strings.Join
with a finite number of elements into simple string concatenations. The reason is that these calls might be used on hot-paths for code, for example: aws/aws-sdk-go#729The results might be small, see below for my machine, but any speed improvement is a good one imho
Thank you.
The text was updated successfully, but these errors were encountered: