-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add Go compiler directive 'noescape' to assembly implementations #1
Conversation
Without this directive Go considers that `data []byte` escapes from the function, and forces allocation on the heap even for values which can perfectly stay on the stack. This removes extra allocation when value passed in is not on the heap already. See also: golang/go#4099
These hints allow compiler to avoid allocating argument on the heap,
|
This LGTM, thank you! (Sorry about the late reply, I didn't get a notification for this for some reason) |
@smira is there a way to get this to show up in a benchmark? func BenchmarkNoescape32(b *testing.B) {
var buf [8192]byte
for i := 0; i < b.N; i++ {
Sum32(buf[:])
}
} Shows no allocation both before and after for me. |
Scratch that, func BenchmarkNoescape32(b *testing.B) {
for i := 0; i < b.N; i++ {
var buf [8192]byte
Sum32(buf[:])
}
} shows the difference. I'll commit that benchmark (and the corresponding 128 one) once I'm on a network not blocking port 22. Thanks again! |
I've pushed the benchmark. I also reran comparisons against spaolacci/murmur3 and ended up removing the 32 bit assembly implementation altogether. The Go compiler has caught up and matches or beats my prior implementation, so there's no reason to leave it around. Lastly, this repo now supports go modules (with a basic go.mod). Thanks again for the reminder to touch up this repo. |
Thanks a lot! Last thing I had on my mind, but I haven't got to implement that is to have optimized version of 128-bit murmur3 when I have to hash two byte slices concatenated. If I really concatenate them that leads to memory copy, if I don't concatenate them I have to use |
So you were thinking something along the lines of... ManySum128(data ...[]byte) ? |
yep, exactly. I have two byte slices in my case, and I have to do:
This implementation is still Go-based, but slices are somewhat large, several KB - 1MB, I don't know if assembly version would be giving enough performance increase to make it worth the effort. In the |
Coming back to this, I considered pursuing this but the use case is a little obscure to add a one off function for it: to be complete with the existing functions would basically require adding 6 or 12 new functions. |
yep, agreed, I think it would be too much work and support coming forward for such usecase. thanks! |
Without this directive Go considers that
data []byte
escapes from thefunction, and forces allocation on the heap even for values which can
perfectly stay on the stack.
This removes extra allocation when value passed in is not on the heap
already.
See also: golang/go#4099