From 150de948eeceac0ace02a0f93a9a7a1f7421d744 Mon Sep 17 00:00:00 2001 From: Martin Möhrmann Date: Sat, 10 Sep 2016 22:44:00 +0200 Subject: cmd/compile: intrinsify slicebytetostringtmp when not instrumenting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit when not instrumenting: - Intrinsify uses of slicebytetostringtmp within the runtime package in the ssa backend. - Pass OARRAYBYTESTRTMP nodes to the compiler backends for lowering instead of generating calls to slicebytetostringtmp. name old time/op new time/op delta ConcatStringAndBytes-4 27.9ns ± 2% 24.7ns ± 2% -11.52% (p=0.000 n=43+43) Fixes #17044 Change-Id: I51ce9c3b93284ce526edd0234f094e98580faf2d Reviewed-on: https://go-review.googlesource.com/29017 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/runtime/string.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/runtime/string.go') diff --git a/src/runtime/string.go b/src/runtime/string.go index 2263e16410..4c4b736c63 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -109,17 +109,20 @@ func rawstringtmp(buf *tmpBuf, l int) (s string, b []byte) { return } +// slicebytetostringtmp returns a "string" referring to the actual []byte bytes. +// +// Callers need to ensure that the returned string will not be used after +// the calling goroutine modifies the original slice or synchronizes with +// another goroutine. +// +// The function is only called when instrumenting +// and otherwise intrinsified by the compiler. +// +// Some internal compiler optimizations use this function. +// - Used for m[string(k)] lookup where m is a string-keyed map and k is a []byte. +// - Used for "<"+string(b)+">" concatenation where b is []byte. +// - Used for string(b)=="foo" comparison where b is []byte. func slicebytetostringtmp(b []byte) string { - // Return a "string" referring to the actual []byte bytes. - // This is only for use by internal compiler optimizations - // that know that the string form will be discarded before - // the calling goroutine could possibly modify the original - // slice or synchronize with another goroutine. - // First such case is a m[string(k)] lookup where - // m is a string-keyed map and k is a []byte. - // Second such case is "<"+string(b)+">" concatenation where b is []byte. - // Third such case is string(b)=="foo" comparison where b is []byte. - if raceenabled && len(b) > 0 { racereadrangepc(unsafe.Pointer(&b[0]), uintptr(len(b)), -- cgit v1.3-5-g9baa