--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/C9X2NM4AAJ4C.3UHAPTBAIMZQY%40themachine.
On Mar 14, 2021, at 11:37 AM, Jason E. Aten <j.e....@gmail.com> wrote:
> I'm no authority here, but I believe a large (major?) part of the Cgo overhead is caused by scheduling overhead. As I understand it, a C function call is non-preemptible and the Go runtime don't know whether the call will block.
But that part would be handled by the C-compiler-that-knows-Go inserting the pre-emption points just like the Go compiler does into the generated code. Or the same checks for blocking.
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/0ac6ac9e-ed99-4536-a8b0-44674f8b85a5n%40googlegroups.com.
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.
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 <ia...@golang.org> wrote:
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXgvi5DfffbSUHn0WWq4sLtYW4bn7R2hhaDSgoWyvKGeA%40mail.gmail.com.
By the way, this existed at one point. Early versions of the Go toolchain included C compilers (6c, 8c, etc.) designed to work together nicely with Go code. If I remember right, most of the Go runtime was written in C, and compiled with these compilers. But they used an unusual dialect of C (which came from Plan 9) instead of ANSI C, so they couldn't compile most C libraries.
When the Go runtime was translated from C to Go, these compilers
were dropped.
If you wanted to revive them and make them ANSI compliant, you would need to write a new libc that calls into the Go standard library for its system calls—because C code compiled with this compiler would not be able to call into the system libc without CGo!
Andy
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/028ecd62-5f9f-4cb6-95df-a0b48ff3d825n%40googlegroups.com.
On Mar 15, 2021, at 3:58 PM, Andy Balholm <andyb...@gmail.com> wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/bf013837-7b1c-6cb3-801f-03776ec5cdd4%40gmail.com.