Skip to content
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

Avoiding string to bytes conversion example is wrong. #2

Open
cuonglm opened this issue Apr 19, 2023 · 0 comments
Open

Avoiding string to bytes conversion example is wrong. #2

cuonglm opened this issue Apr 19, 2023 · 0 comments

Comments

@cuonglm
Copy link

cuonglm commented Apr 19, 2023

At b85fa2d, in this file, both BenchmarkBad and BenchmarkGood causes []byte("Hello world") escape to heap:

 $ go test -c -gcflags=-m p_test.go 
# command-line-arguments [command-line-arguments.test]
./p_test.go:8:19: b does not escape
./p_test.go:11:14: ([]byte)("Hello world") escapes to heap
./p_test.go:14:13: ... argument does not escape
./p_test.go:14:14: a escapes to heap
./p_test.go:17:20: b does not escape
./p_test.go:19:17: ([]byte)("Hello world") escapes to heap
./p_test.go:23:13: ... argument does not escape
./p_test.go:23:14: a escapes to heap
# command-line-arguments.test
_testmain.go:39:6: can inline init.0
_testmain.go:47:24: inlining call to testing.MainStart
_testmain.go:47:42: testdeps.TestDeps{} escapes to heap
_testmain.go:47:24: &testing.M{...} escapes to heap

The reason BenchmarkBad is worse because the escaping happens inside the loop, it does not relate to string to bytes conversion operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant