fastcgo 通过汇编跳板进行快速(但不安全)的 Cgo 调用。受 rustgo 的启发。UnsafeCall 函数接受一个指向 Cgo 函数的指针,并将其传递给 Cgo 执行。
fastcgo 通过汇编跳板进行快速(但不安全)的 Cgo 调用。受 rustgo 的启发。UnsafeCall 函数接受一个指向 Cgo 函数的指针,并将其传递给 Cgo 执行。
Fast (but unsafe) Cgo calls via an assembly trampoline. Inspired by
rustgo. The UnsafeCall* function
takes a pointer to a Cgo function and a number of arguments and
executes the function on the "system stack" of the thread the current
Goroutine is running on. Usage looks like:
package hello
// #include
// #include
// void hello(uint64_t arg) {
// printf("Hello, C: %lld\n", arg)
// }
import "C"
import (
"github.com/petermattis/fastcgo"
)
func Hello(arg uint64) {
fastcgo.UnsafeCall4(C.hello, arg, 0, 0, 0)
}The upshot is significantly faster transitions into C/C++:
~/go/src/github.com/petermattis/fastcgo master go test -run=- -bench=. ./bench/
...
BenchmarkGO-8 2000000000 1.90 ns/op
BenchmarkCGO-8 30000000 60.1 ns/op
BenchmarkFastCGO-8 300000000 4.63 ns/op
...WARNING: No attempt is made to play nice with the Go scheduler or GC. The goroutine executing a fastcgo call will never be interrupted and will delay the starting or completion of GC until it finishes.
暂无开放 Issues,或尚未同步最近议题。