3 ms·
This looks really cool! Is there any overhead with using these bindings as opposed to using Swift and calling the APIs directly?
by coetry 6y ago
This looks really cool! Is there any overhead with using these bindings as opposed to using Swift and calling the APIs directly?
- axaxs 6y ago> Is there any overhead with using these bindings Not the author, but yes. Go calling C is expensive, and that's precisely how this works. Whether or not that matters for your use case is another topic.
- lsllc 6y agoThere's a bit of a write-up here: https://www.cockroachlabs.com/blog/the-cost-and-complexity-of-cgo/ https://www.cockroachlabs.com/blog/the-cost-and-complexity-o... In their benchmark, calling a `func() {}` in Go vs a `void foo() {}` in C (via CGo) is almost 100x faster. $ go test -bench . -gcflags '-l' # disable inlining for fairness BenchmarkCGO-8 10000000 171 ns/op BenchmarkGo-8 2000000000 1.83 ns/op EDIT: And then you still have the extra overhead when using `C.CString` and `C.GoBytes` if you're passing those sorts of arguments to C.
- _ph_ 6y agoBut if the called function takes more than 200ns to execute, the overhead is less than 50%. Which probably is true for most relevant functions in an API
- _ph_ 6y agoGo calling C is expensive compared to the normal function call overhead, but if the called function does significant work, should not introduce too much overhead.
- MaxBarraclough 6y ago> Go calling C is expensive Is this true even if only primitives are passed and returned? If so, why? For comparison, Java is fast at that these days, if I understand correctly. (Interesting related reading regarding Java: https://web.archive.org/web/20160304055443/http://nerds-central.blogspot.co.uk/2012/04/extreme-jni-performance.html https://web.archive.org/web/20160304055443/http://nerds-cent... )
- progrium 6y agoThis is a good question that should be added in the readme. Would love an issue for it to also collect data