I am profiling a Go program that calls into C using cgo, and then
tries to get a pointer to unsafe data. In the profiling, I see that
over 62% of the time is spent in a call which is of the form
func getBytes(val *C.MDB_val) []byte {
return
(*[valMaxSize]byte)(unsafe.Pointer(val.mv_data))[:val.mv_size:val.mv_size]
}
Full code for context:
https://github.com/bmatsuo/lmdb-go/blob/master/lmdb/txn.go#L399
what happens with unsafe.Pointer? Doesnt it just return a pointer why
should it take up so much time in the CPU profile?
Here is the profile output:
$ go tool pprof badger-bench.test lmdb.out
Entering interactive mode (type "help" for commands)
Showing top 10 nodes out of 44 (cum >= 10ms)
flat flat% sum% cum cum%
120ms 48.00% 48.00% 120ms 48.00%
github.com/bmatsuo/lmdb-go/lmdb.(*Txn).bytes
80ms 32.00% 80.00% 80ms 32.00% runtime.cgocall
10ms 4.00% 84.00% 10ms 4.00% fmt.(*pp).printArg
10ms 4.00% 88.00% 10ms 4.00%
github.com/dgraph-io/badger/y.AssertTruef
10ms 4.00% 92.00% 10ms 4.00% runtime.(*gcWork).put
10ms 4.00% 96.00% 10ms 4.00% runtime.adjustframe
10ms 4.00% 100% 20ms 8.00% runtime.greyobject
0 0% 100% 10ms 4.00% fmt.(*pp).doPrintf
0 0% 100% 10ms 4.00% fmt.Sprintf
0 0% 100% 10ms 4.00%
github.com/bmatsuo/lmdb-go/lmdb.(*Env).Close
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.