There is probably some room to get faster, but I don't think there is
very much. If you need to call into a C API often, it's going to work
better if you can batch your calls to reduce the number of times you
have to cross the language boundary.
The Go standard library only calls into C in two places: to look up
user names in the os/user package, and to resolve network names in the
net package. For things like sockets the Go standard library issues
system calls directly.
It is of course possible that you are doing something wrong, but the
slowness of calls from Go to C is a known issue.
There is no penalty for the call to WSASendTo.
on windows, basically every call into DLL is a cgo call.
on windows, basically every call into DLL is a cgo call.what about Linux then? Are syscalls' cost 0?
Sadly I am not familiar with Linux so.. is it possible to call OpenGL via syscall on Linux?
It is possible on Windows.
There's a technique that may be used to pretty much eliminate that
cost with certain APIs, and OpenGL is especially adequate for it:
instead of having Go call C on every single API, you can buffer a
number of calls in memory, and then cross the bridge just once for
flushing. This will eliminate the 10x pretty much entirely. I'm
planning to do that with the qml package when the time comes.
Another relevant detail which perhaps you already have in mind is that
with modern OpenGL you can load most of the content in the graphics
card memory, and then manipulate it there, instead of reloading it for
every frame.
I actually wrote an OpenGL wrapper generator in Go [1] which can be used with QML. It allows for batching of OpenGL calls into a small stack and on the C side of things executes them in large batches using a jump table.Now, there is the cost of that additional stack and I've not bench-marked the performance cost of that.Stephen
Yes, there is a cost, and yes, there are possible solutions, and
indeed, you'd have to spend time implementing them.
On Sunday, April 27, 2014 12:25:03 PM UTC+8, Stephen Gutekanst wrote:
I actually wrote an OpenGL wrapper generator in Go [1] which can be used with QML. It allows for batching of OpenGL calls into a small stack and on the C side of things executes them in large batches using a jump table.Now, there is the cost of that additional stack and I've not bench-marked the performance cost of that.
nice! Very very clever.But the very fact something like this becomes necessary should be a sign that something is deeply wrong in Go. If this is the "solution" the result is that it will simply send any programmer interested in interacting with native API running away to better alternatives.
Also the std Go libs do not use this system, so, as it is at the moment, on Windows any Go program is paying a huge 10x price for every interaction with the OS.
I think you misunderstand, or exaggerate, what 10x overhead mentioned by iant means.it means the function call costs ~10x as much as a normal Go call, but the time to actuallydo the work should be the same. If the function call overhead is too big, then it simply meansthe function is doing too little.For most windows "syscalls" used by Go, that is never a problem, because doing a single IOwill require much more time than 10 function calls.
--
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/RzA3HLI7ZKI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
I'm sorry but I don't think that the function call overhead is too bad for game development either. Immediate mode is deprecated in OpenGL anyways, if you're using immediate mode you should be expecting bad performance period.
There are very few game development C libraries that require such a large amount of function calls, the main offenders are OpenGL and perhaps a few physics engines, but again most of the time the cost here is negligible (and when it isn't: make fewer C calls). I don't think it's as big of a deal as you make it out to be.
Go uses a different calling convention than C and C++ and honestly I don't think it's outrageous at all that there is an overhead for calling C functions, especially given the fact that the reason (AFAIK) the overhead is there is because of Go uses split stacks which is needed for goroutines to not consume lots of memory.
There are ways to work around these issues today and Go still looks like a better alternative than C for my game development projects. Maybe the situation will improve in the future (perhaps Go could do batching of C calls auto-magically or something), but it's not the case today and I still don't think it's a deal-breaker.
It's fine that you're not interested in pursuing the ideas offered,
but it's uncandid to continue discoursing as if they were not given
and the problem was completely unavoidable.
Not 15k lines either, but sure, having no interest on things is completely fine.
gustavo @ http://niemeyer.net
--
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.
I do completely think however that making a game similar or better than the one you have linked would be possible in Go.
Hello,I am a big fan and supporter of Go and try to evangelize everywhere and anytime I can.I am using Go to write the race server side for Assetto Corsa (www.assettocorsa.net) with good results, BTW multiplayer (thus the Go race server) is going live next week so wish me luck on that :P .. however...Trying to explore the use of Go for the client side of a 3D application (game or simulation) I started measuring the cost of calls made to C (tried both standard CGO and syscall on windows) and the results are discouraging to say the least:I tried an "old style" OpenGL immediate mode benchmark and used a number of calls similar to the one I see in Assetto Corsa.. well, the bad news is that where my control application in C is taking 1ms to issue a couple of clear calls and tiny triangles (to avoid having the GPU influencing the results) the equivalent Go version takes about 9ms! That's more than half of the available time for a 60fps rendering application gone in just overhead for calling into C... a showstopper..NET performs much better on the same test taking about 1.42ms . In different tests (not using OpenGL but other calls to C libraries) the new .Net Native is halfway between C and traditional .Net .. Rust and D are on par with C, so 0 cost, but that's understandable considering they don't have a GC and goroutines infrastructure to manage.This is on Go 1.2.1 windows/386now to the questions:1) Is there a margin for Go to get better at this? Or should we just give up on it for any kind of application that need a high rate of communication with a native API? I am thinking gui, 3d graphics, physics, audio.2) I am also wondering if this costs is somehow lower on platforms that get traditionally more love from Go devs such as Linux and Mac? I don't have a Linux install handy to give it a go right now.3) I haven't dug into the Go standard library but I suppose there are parts (sockets?) where it needs to call C somehow, is this overhead hurting Go in other places where perhaps Go devs might be more sensible?4) Is it possible I am doing something wrong? How to go about to improve the situation?
they both run at around the same speed, with the majority of the runtime being spent in glDrawArrays.
That implies all your code ever does is to call empty C functions.
If you'd like to see people collaborating to solve that problem, a good start would be an actual benchmark.
gustavo @ http://niemeyer.net
--
You should profile it. I did a benchmark of Go OpenGL performance that I haven't got around to publishing, and running it through the Go profiler I found that the use of immediate mode did a bunch of stupid memory allocation stuff. Changing it to avoid immediate mode however resulted in performance comparable to C, so I highly recommend you don't judge Go OpenGL performance by immediate mode.