-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/compile/internal/base: GODEBUG=zerocopy=0 tag doesn't seem to work #64427
Comments
CC @golang/compiler. |
I haven't looked closely, but at first glance I think If you change your |
This is not a GODEBUG setting, but a compiler command-line debug flag. Try |
``
I modified use case 3 and use case 4 as per your guidance and it looks like yes. Thanks! var result []byte
func BenchmarkByteStyle(b *testing.B) {
str := `{"default":{"common":{"pet":{"five":"aa","four":"bb","one":"cc","three":"dd ","two":"ee"},"relation":{"father":"ff","mother":"mm","wife":"ww"}}}}`
result = []byte(str)
}
func BenchmarkWithUnsafe(b *testing.B) {
str := `{"default":{"common":{"pet":{"five":"aa","four":"bb","one":"cc","three":"dd ","two":"ee"},"relation":{"father":"ff","mother":"mm","wife":"ww"}}}}`
sh := (*reflect.StringHeader)(unsafe.Pointer(&str))
bh := reflect.SliceHeader{
Data: sh.Data,
Len: sh.Len,
Cap: sh.Len,
}
result = *(*[]byte)(unsafe.Pointer(&bh))
} go test -test.bench=".*" -benchmem
goos: darwin
goarch: arm64
pkg: bc
BenchmarkTest1-8 36800676 32.41 ns/op 192 B/op 1 allocs/op
BenchmarkTest2-8 143107815 8.233 ns/op 0 B/op 0 allocs/op
BenchmarkTest3-8 40202856 29.65 ns/op 192 B/op 1 allocs/op
BenchmarkTest4-8 942046788 1.271 ns/op 0 B/op 0 allocs/op
PASS
ok bc 6.996s |
I have a misunderstanding about the use of GODEBUG, thanks for all the replies. I think this issue can be closed, this is not a bug. Sorry to bother everyone |
Go version
go version devel go1.22-769469fb5e Fri Nov 24 10:25:33 2023 +0800 darwin/arm64
What operating system and processor architecture are you using (
go env
)?What did you do?
CL520599 added optimization for zero memory overhead of string-->[]byte. CL520600 enables zerocopy by default.
I want to test and compare,
when go version is 1.21
when go version is 1.22
Compared with 1.21, it is indeed optimized for sting-->[]byte.
But also in the go 1.22 environment, GODEBUG=zerocopy=0 go test -test.bench="." -benchmem or GODEBUG='zerocopy=0' go test -test.bench="." -benchmem does not work at all, BenchmarkTest3-8 still has no memory overhead
What did you expect to see?
BenchmarkTest3-8 should have memory allocated when the GODEBUG=zerocopy=0 tag is added.
What did you see instead?
BenchmarkTest3-8 has no memory overhead.
When I remove Debug.ZeroCopy = 1 in the source code src/cmd/compile/internal/base/flag.go, recompile and execute, I can see that BenchmarkTest3-8 has memory overhead as expected.
The text was updated successfully, but these errors were encountered: