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

Use range based zeroing for >= Go 1.5 #286

Closed
jrick opened this issue May 27, 2015 · 0 comments · Fixed by #287
Closed

Use range based zeroing for >= Go 1.5 #286

jrick opened this issue May 27, 2015 · 0 comments · Fixed by #287
Assignees

Comments

@jrick
Copy link
Member

jrick commented May 27, 2015

Go 1.5 optimizes code such as the following:

for i := range slice {
        slice[i] = 0
}

to a duff's device to zero memory in the slice. With Go tip, it benchmarks faster than the zero.Bytes function.

BenchmarkRange32    300000000            4.14 ns/op
BenchmarkRange64    300000000            4.26 ns/op
BenchmarkBytes32    200000000            7.91 ns/op
BenchmarkBytes64    100000000           13.6 ns/op

The range-based zero should be enabled for all versions but Go 1.4 using build tags. When Go 1.5 is released, we will stop supporting Go 1.3, so only 1.4 needs the custom implementation. After 1.6 is out, the custom implementation can be removed entirely.

@jrick jrick self-assigned this May 27, 2015
jrick added a commit to jrick/btcwallet that referenced this issue May 27, 2015
jrick added a commit to jrick/btcwallet that referenced this issue May 27, 2015
jrick added a commit to jrick/btcwallet that referenced this issue May 27, 2015
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

Successfully merging a pull request may close this issue.

1 participant