Hello fellow gophers, Here is a helpful link that gives an overview of some of what impacts cgo performance, including the slides have pointers into the code for anyone interested in going deeper:
https://speakerdeck.com/filosottile/why-cgo-is-slow-at-capitalgo-2018 That was a 2018 presentation “Why cgo is Slow” from Filippo Valsorda from the core Go team. (To my knowledge, I don’t know that there is a video of that talk, but I’d be curious if anyone has a pointer to a video, including even shaky handheld mobile video). And here are some quick pointers to some older related issues: https://github.com/golang/go/issues/42469 https://github.com/golang/go/issues/16051 https://github.com/golang/go/issues/9704 If anyone is feeling curious, benchmarking performance of cgo across Go releases could be helpful to spot any slowdowns. For example, someone could run this trivial benchmark across recent releases: https://github.com/golang/go/issues/9704#issuecomment-498812185 Or pick something from here to run across releases: https://github.com/golang/go/issues/42469#issuecomment-746947396 Or some other benchmark across releases. On the scheduler front, I would be curious about this older comment from Ian: ——— “In Go 1.8 when a goroutine calls into C, it is still holding a GOMAXPROCS slot and blocking other goroutines from running. Only if it is running in C for more than 20 microseconds or so will the system monitor thread decide that it is blocked in C code and activate another goroutine. The fact that your system performs better than you increase GOMAXPROCS makes me suspect that there is something to improve in that area of the code.” ——— .... where that comment was later used as part of an explanation FAQ on why dqlite moved from Go to C (https://dqlite.io/docs/faq), and whether or not that explanation is currently accurate: ——— “The first prototype implementation of dqlite was in Go, leveraging the hashicorp/raft implementation of the Raft algorithm. The project was later rewritten entirely in C because of performance problems due to the way Go interoperates with C: Go considers a function call into C that lasts more than ~20 microseconds as a blocking system call, in that case, it will put the goroutine running that C call in waiting queue and resuming it will effectively cause a context switch, degrading performance (since there were a lot of them happening).” ——— Regards, thepudds > On Mar 15, 2021, at 3:24 PM, Ian Lance Taylor <i...@golang.org> wrote: > > On Mon, Mar 15, 2021 at 12:17 PM Jason E. Aten <j.e.a...@gmail.com> wrote: >> >>> On Monday, March 15, 2021 at 12:58:38 PM UTC-5 Ian Lance Taylor wrote: >>> >>> I think it is too strong to say that the scheduler is the "bottleneck" >>> in calling C code, but I believe that the operations required to tell >>> the scheduler what is happening to the goroutine are the most costly >>> parts of a call into C code. >> >> >> Thanks Ian! I looked through >> https://github.com/golang/go/tree/master/src/cmd/cgo but couldn't >> locate where the CGO communication with the scheduler happens. Could you >> point out the code? > > It is in runtime.cgocall, notably the calls to entersyscall and > exitsyscall. Also pay attention to runtime.cgocallbackg, which is > invoked when calling back from C to Go. Both functions are in > src/runtime/cgocall.go. It will help to review the long comment at > the start of that file. > > Ian > > -- > You received this message because you are subscribed to a topic in the Google > Groups "golang-nuts" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/golang-nuts/K-If1Wh_6aA/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXgvi5DfffbSUHn0WWq4sLtYW4bn7R2hhaDSgoWyvKGeA%40mail.gmail.com. -- 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 golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/25FBEE12-FA0D-47FC-A76B-9CD517033A11%40gmail.com.