You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, when one calls cdb.Get(key), if the caller has the key on stack, like key := [4]byte {0,1,2,3}, the Go compiler decides that the value "escapes" and thus it must be allocated on the heap. (The reason being that cdb.hash uses that key value, and an arbitrary implementation might decide to keep a slice of the key.)
This can be spotted with the following simple test:
cipriancraciun@e860a79 -- a simple patch of the Get function that uses the NoEscapeBytes, which tricks the Go compiler into not requiring the key to be heap allocated;
The performance improvements are about ~10ns per call, which if also using the mmap patch sent earlier represents 50% of the total runtime.
Currently, when one calls
cdb.Get(key)
, if the caller has the key on stack, likekey := [4]byte {0,1,2,3}
, the Go compiler decides that the value "escapes" and thus it must be allocated on the heap. (The reason being thatcdb.hash
uses thatkey
value, and an arbitrary implementation might decide to keep a slice of the key.)This can be spotted with the following simple test:
If comipilled as
go test -gcflags -m
one can see the message./noescape_test.go:32:3: moved to heap: keyOnStack
.The following two patches solve this issue:
NoEscapeBytes
function based on what Go'sruntime
does internally -- https://github.com/golang/go/blob/ecb2f231fa41b581319505139f8d5ac779763bee/src/runtime/stubs.go#L172-L181Get
function that uses theNoEscapeBytes
, which tricks the Go compiler into not requiring the key to be heap allocated;The performance improvements are about ~10ns per call, which if also using the
mmap
patch sent earlier represents 50% of the total runtime.The text was updated successfully, but these errors were encountered: