Hi, I run an benchmark on my C-Library using GO frontend… I figure out that GO has an remarkable performance lost in calling a C function: example calling my Function “MqReadD”
my C-Code (#1) consume 10ms… the GO Wrapper (#2) and the CGO wrapper (#3) consume together 110ms … -> as you see only 10% of the time is the real work and 90% is the GO/CGO overhead.
-> some ideas available to speedup GO code ?
(I already use export GODEBUG=cgocheck=0
to get best performance.)
(pprof) list ReadD
Total: 2.71s
ROUTINE ======================== MqReadD in ...NHI1/theLink/libmsgque/read_mq.c
0 10ms (flat, ■■■) 0.37% of Total
. . 1204: struct MqS * const context,
. . 1205: MQ_DBL * const valP
. . 1206:)
. . 1207:{
. . 1208: check_CTX(MQ_HDL_NULL_ERROR(MqC))
. 10ms 1209: return sReadA8(context, (union MqBufferAtomU * const) valP, MQ_DBLT);
. . 1210:}
. . 1211:
. . 1212:enum MqErrorE
. . 1213:MqReadC (
. . 1214: struct MqS * const context,
ROUTINE ======================== gomsgque.ReadD..1gomsgque.MqC in /.../NHI1/theLink/gomsgque/src/gomsgque/MqC.go
0 120ms (flat, ■■■) 4.43% of Total
. . 1282:}
. . 1283:
. . 1284:/// \refdoc{ReadD}
. . 1285:func (this *MqC) ReadD () float64 {
. . 1286: hdl := this.getCTX()
. 10ms 1287: var val_out C.MQ_DBL
. 110ms 1288: var errVal C.enum_MqErrorE = C.MqReadD (hdl, &val_out)
. . 1289: if (errVal > C.MQ_CONTINUE) { MqErrorC_Check(C.MQ_MNG(hdl), errVal) }
. . 1290: return (float64)(val_out)
. . 1291:}
. . 1292:
. . 1293:/// \refdoc{ReadF}
ROUTINE ======================== gomsgque._Cfunc_MqReadD in /tmp/go-build/b001/_cgo_gotypes.go
0 110ms (flat, ■■■) 4.06% of Total
. . 3028://extern _cgo_a12d8325d15e_Cfunc_MqReadC
. . 3029:func _cgo_a12d8325d15e_Cfunc_MqReadC(p0 _Ctype_MQ_CTX, p1 *_Ctype_MQ_CST) uint32
. . 3030:
. . 3031:func _Cfunc_MqReadD(p0 _Ctype_MQ_CTX, p1 *_Ctype_MQ_DBL) uint32 {
. . 3032: defer syscall.CgocallDone()
. 60ms 3033: syscall.Cgocall()
. 10ms 3034: r := _cgo_a12d8325d15e_Cfunc_MqReadD(p0, p1)
. . 3035: return r
. 40ms 3036:}
. . 3037://extern _cgo_a12d8325d15e_Cfunc_MqReadD
. . 3038:func _cgo_a12d8325d15e_Cfunc_MqReadD(p0 _Ctype_MQ_CTX, p1 *_Ctype_MQ_DBL) uint32
. . 3039:
. . 3040:func _Cfunc_MqReadF(p0 _Ctype_MQ_CTX, p1 *_Ctype_MQ_FLT) uint32 {
. . 3041: defer syscall.CgocallDone()