Jump to content

  • Log In with Google      Sign In   
  • Create Account

Go for video game programming?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
19 replies to this topic

#1 SteveDeFact0   Members   -  Reputation: 151

Like
0Likes
Like

Posted 27 April 2014 - 11:10 AM

I was watching a presentation on Go and I started wondering if it would be more efficient than C++ for my game engine? I mean obviously multithreading can be done in C++ but it would appear that Go would streamline the process. So really my question is does Go have any down side? Like for example even though a language like C# or Visual Basic is easier to use, grabage collection amoung other things tends to make it run much slower than a program written in C++. So is there anything simular to that with Go?



Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 16401

Like
15Likes
Like

Posted 27 April 2014 - 11:20 AM

Go is garbage collected, but whether or not that's a problem depends a lot on what you're trying to use it for.

Library support for things like game development is a little constrained right now, but the selection is growing.

In general, though, you shouldn't pick the language just because it sounds "more efficient." Use it because of the language and its characteristics. What helps you be productive is far more important than a few billionths of a second.

#3 ProtectedMode   Members   -  Reputation: 1284

Like
3Likes
Like

Posted 27 April 2014 - 11:49 AM

I agree with ApochPiQ. I just want to add that the presentation you looked at was probably from some party that's a fan of Go, so maybe you should try to search for a list of disadvantages too?



#4 SeanMiddleditch   Members   -  Reputation: 7174

Like
6Likes
Like

Posted 27 April 2014 - 02:08 PM

I was watching a presentation on Go and I started wondering if it would be more efficient than C++ for my game engine? I mean obviously multithreading can be done in C++ but it would appear that Go would streamline the process. So really my question is does Go have any down side? Like for example even though a language like C# or Visual Basic is easier to use, grabage collection amoung other things tends to make it run much slower than a program written in C++. So is there anything simular to that with Go?


A close friend who is a huge Go proponent and has written a game engine in Go, has have a number of other people. While I personally have a number of things I dislike about Go, the question of whether it can work for games is a clear "yes." Game engines have also been written in Haskell and any number of other "games unfriendly" languages.

Garbage collection does _not_ make Go run "much slower" than C++. The number of C# games (including most Unity titles) should illustrate that it is entirely possible to make a real game with garbage collection. What garbage collection does is add an unpredictable spike in processing time, which can result in missed frames and general jankiness (if you aren't very careful). You need to be highly aware of the GC, what triggers it (allocations, generally), and what code to avoid running during the game loop (many features in languages like C# or Go don't _look_ like they're allocating memory but actually are, and you need to know what those are and how to avoid using them); then you can avoid most of the problems of GC.

The biggest problem you're liking to run into with Go is the lack of generics (templates in C++ lingo) and the unnecessary boxing (memory allocations) that containers require. Note that due to JVM limitations, Java also has this problem despite having generics. C# and Rust however support "real" generics that don't have this problem. C in a way _does_ have this problem, in that you either have to use some kind of generalized container that must box values or you have to reimplement your containers (or use macros) for each type, which is a very big real-world case where C++ (or Rust) is more efficient both in terms of performance and development than C is thanks to templates.

If you can't completely eliminate invocations of the GC, you're going to have a problem making games that use up all available CPU time for meaningful processing, as there simply won't be any place for a GC to run without causing frame skips. Unless you're DICE or Rocksteady or some other AAA developer, though, it is exceedingly unlikely that you are going to be in such a situation.

I'm personally of the opinion that Go is simply not the best fit for games. If you're looking for Go's niceties over C++ (cleaner non-C-poisoned syntax, simple and efficient threading model, etc.) you should instead look at Rust. Again, that is just opinion. I stick with C++ since I find it easy enough to build Go-like or Rust-like threading libraries in C++, and C++ has a number of other benefits over everything else (wide industry support being a big one). If you're interested in exploring Rust, this page has some useful links on it for Rust game development.

#5 SeraphLance   Members   -  Reputation: 1454

Like
0Likes
Like

Posted 28 April 2014 - 01:49 PM

There's nothing intrinsically wrong with it, but I personally don't like Go's hardline stance against generics.  It's a painful productivity miss.
 

Of all the "C/C++ esque" languages that have cropped up in recent years, D honestly seems to have the best basis along with Go (though Rust is certainly interesting).  That's probably the only language out there where you can write code and say "...did I just accidentally do template metaprogramming?"  It's liberating.



#6 swiftcoder   Senior Moderators   -  Reputation: 10367

Like
3Likes
Like

Posted 28 April 2014 - 03:37 PM


Of all the "C/C++ esque" languages that have cropped up in recent years, D honestly seems to have the best basis

My core problem with D in this respect is that it *is* just a C++ clone with some (but far from all) rough edges rounded off.

 

Sure it makes template metaprogramming simpler than C++, but it doesn't really add/enable a whole lot else. No native support for high concurrency, no attempt at a new memory model, no attempt to simplify or improve the basic programming model, and so forth...

 

Rust is very interesting on a variety of fronts: coroutines/fibers without shared mutable state is a proven model for massive concurrency, explicit region support is the first attempt we've seen in a long time to sidestep the whole reference counting vs garbage collection debacle entirely, and the system of traits/implementations/structs might finally get us out of the many holes that inheritance-based OOP has dug (the dreaded diamond inheritance in C++, implementation vs interface inheritance, etc).


Edited by swiftcoder, 28 April 2014 - 03:37 PM.

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#7 kunos   Crossbones+   -  Reputation: 2207

Like
1Likes
Like

Posted 29 April 2014 - 08:05 AM

I am using Go for a pet 3D project and I also use it in production for the server side of my latest game... here's my recap:

 

PRO

 

- Build system.. it's pure awesomeness: no makefiles, super fast compile times, good package managing with Git integration out of the box

- Fast and getting faster for code written in Go at every release.. for most common task it's almost with C++ at least from my benchmarks.

- Easy to interface C libraries. C++ interface exist but I haven't tried it yet

- Very simple to learn.. it's a very small language

- Duck typing.

- Great support for massive concurrency

- Gofmt.. forces an unique style of code formatting: the Go style. All Go code on the planet is formatted the same way.. this hugely improves readability.

- Good IDE support. I use LiteIDE ( https://code.google.com/p/liteide/ ) It's designed exclusively for Go and it's awesome. There are Go "modes" for Emacs, Vi, Eclipse, Sublime Text and a lot more.. and, because of go "no makefiles" "no project files" approach, it's one of the few languages you can really use without and IDE. Although I really suggest LiteIDE.

 

CONS

- No operator overloading. 3D math code looks ugly

- No function overloading.. need to use suffixes a-la OpenGL

- Calling C is somehow expensive.. there are ways to go around the problem but it is something to keep in mind when doing 3D work... every API call comes with an attached cost. Due to the language current architecture this cost doesn't seem to be likely to go away.

- Only supports "desktop" environments (Win, Linux, Mac) no Android yet (but there are somethings moving there and the presence of Google might do good things) or other mobile, no consoles support.

 

I don't take sides on the great "Go generics" war on the internet.. I find I can happily live without, but I wouldn't mind them either IF they can be implemented without bloating the language.

All in all, it's a joy to use Go although its minimalist approach often translates in a LOT of code repetition.. but it's beautiful code nevertheless. It's also a language that "trusts" the programmer.. it's a different philosophy of design.. where other languages seem to push programmers into writing in a way as to defend themselves from an horde of maniacs by having constructors, lots of level of encapsulation and so on.. Go's is much more permissive and it relies more on common sense and code documentation.

It's a programmers' for programmers language.. more practical and pragmatic than theoretically fit.

 

I agree with people suggesting Rust as another possible future language for game development.. it offers several advantages compared to Go but it comes with a much steeper learning curve (closer to C++ and D) with a less clear syntax compared to Go... plus while Rust is still highly volatile and constantly changing, Go has been ready and used for production for a couple of years.


Edited by kunos, 29 April 2014 - 08:08 AM.

Stefano Casillo
Lead Programmer
TWITTER: @KunosStefano
AssettoCorsa - netKar PRO - Kunos Simulazioni

#8 SeraphLance   Members   -  Reputation: 1454

Like
0Likes
Like

Posted 29 April 2014 - 08:39 AM


My core problem with D in this respect is that it *is* just a C++ clone with some (but far from all) rough edges rounded off.

 

Hah!  In fact, that's what I love about it.  C++ with all the C warts removed is already a fantastic language.  Throw in all the range and slicing stuffs and array manipulation gets as easy as python.  Stuff like Static If actually realizes some of the benefits over generics for people who aren't experts at the C++ labyrinth.  IMO the biggest problem with D is that the GC is basically required if you want to use the standard library.

 

I need to clarify a bit, probably.  While I don't like Rust for a variety of reasons, or Go because of generics, all three are head over heels better than most current "low level languages" out there.  Libraries are a bit lacking for all of them, but if you want something different you can't go wrong with any of them.

 


- Build system.. it's pure awesomeness: no makefiles, super fast compile times, good package managing with Git integration out of the box

 

D has something like this as well (and they even made rdmd as a sort of "joke repl" because of how fast it compiles), though you need dub for good package management.  Not putting down Go or anything mind you, and Rust probably has something similar.  Going away from the C compilation model is the best thing that can happen to a language, and I'm glad to see its finally happening.



#9 kunos   Crossbones+   -  Reputation: 2207

Like
0Likes
Like

Posted 29 April 2014 - 09:08 AM

 

D has something like this as well (and they even made rdmd as a sort of "joke repl" because of how fast it compiles), though you need dub for good package management.  Not putting down Go or anything mind you, and Rust probably has something similar.  Going away from the C compilation model is the best thing that can happen to a language, and I'm glad to see its finally happening.

 

 

My only experiences with D were using Visual D, so I was somehow isolated from the build process. I tried Rust some days ago and ya.. it was able to figure out what files needed to be included in the build process... but I only tried with 2 files so I am not able to confirm how it works for bigger projects.

 

From what I see D has a lot of "nice little things" here and there.. its main attraction is metaprogramming which is way over the head of most devs, people don't really care... it doesn't really have a WoW factor in there and the community looks small and not very vocal nor active, it suffers the fact that it's not saying anything new or interesting.. it looks to me almost as a native C#. Plus it has a bad name that is almost a joke and the docs are not really up there with the competition.

 

Rust (talking about bad names :P what were they thinking? ) also seems to miss the commercial Wow factor.. the slogans are mostly about safety here and there.. a lot of good promises but mostly found in other languages. We'll see what happens when they go v1.0.. but I have a feeling that as of today, if programmers have to face something too complicate they'll just stick with what they have: C++ . The nice bullet in Rust's gun is their potential killer application: Servo.. the new Mozilla browser.. if that will ever come true.

 

Go and the Go community on the other hand, are doing a much better job IMO in promoting the language.. the Go tour is fantastic and there are very interesting tutorials and how-to popping up very often..  plus, the fact that Go has so many controversial features (or lack of) it never fails to generate discussion.. it's a language with a big attitude and I think that is also helping in building a following... it's pushing the right concurrency button. The language seems to be such a perfect fit for something coming out of Google.. it's a big association in people's minds... and, most important thing: once you give it a try, it's hard not to be hooked.


Stefano Casillo
Lead Programmer
TWITTER: @KunosStefano
AssettoCorsa - netKar PRO - Kunos Simulazioni

#10 swiftcoder   Senior Moderators   -  Reputation: 10367

Like
1Likes
Like

Posted 29 April 2014 - 12:38 PM

Rust (talking about bad names tongue.png what were they thinking? ) also seems to miss the commercial Wow factor.. the slogans are mostly about safety here and there.

But that's exactly what developers *should* want. The hard problems in software development aren't addressed by cute little syntactic tricks like C++ template metaprogramming. The hard problems are in highly-concurrent distributed systems requiring high availability and having a low tolerance for failure.

It's precisely this sort of thing that Rust's feature set targets. Unique ownership semantics and implicit/explicit region control allows you to achieve near-automatic memory management without the non-deterministic pauses caused by garbage collectors. Lightweight cooperative multitasking with task-local state is the best know model for highly concurrent systems, especially distributed systems. Tasks also provide a coarse-grained alternative to exception handling, which side-steps the issues of stack annotation and unwinding, and allows you to reboot the entire task on demand in response to failure.

Now, Rust does not actually tick all these boxes at the present moment. For example, their support for async network communication is still pretty much non-existant. But they have a vision here that can drastically improve the process of writing reliable, distributed software. With the obvious caveat that most of the world will go on using whatever technology they currently use, unless it proves a real competitive advantage for companies which embrace it...

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#11 TheChubu   Crossbones+   -  Reputation: 4765

Like
0Likes
Like

Posted 29 April 2014 - 01:28 PM

AFAIK the problem isn't one of "garbage collected language" vs "non garbage collected language". Problem is that Go's particular implementation isn't the fastest around. There isn't a single garbage collection method that all GC'd languages use, they're all different and are targeted for probably different use cases.

 

For example: http://benchmarksgame.alioth.debian.org/

 

If you compare Go's performance with other garbage collected languages (C# on Mono, F# on Mono, Java, Scala, etc) in those benchmarks, you get pretty different results. With Mono based languages its mostly 50/50, whereas with JVM based languages it compares unfavorably on most cases.

 

So even among GC'd languages you can find wildly different results, just like you can't expect to see the same results among compiled languages.

 

I'm not saying to take those numbers as the holy grail of programming language comparisons, but just to show that it isn't just a decision between GC and no GC.


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#12 kunos   Crossbones+   -  Reputation: 2207

Like
0Likes
Like

Posted 29 April 2014 - 05:30 PM

 

Rust (talking about bad names tongue.png what were they thinking? ) also seems to miss the commercial Wow factor.. the slogans are mostly about safety here and there.

But that's exactly what developers *should* want.

 

 

Perhaps.. but the reality is that what programmers want is a language that doesn't get in the way of what I am doing.. and Go is sublime in this... it's actually funny to see the horrified reactions of language elitists and purist when confronted with the current success of Go :P 

 

We'll see what happens with Rust.. I haven't done any serious coding with it yet and I am not planning to until it goes v1.0 and feature an IDE support offering productivity aids like good intellisense (code completion), project navigation and refactoring.

We'll have to see how the rules and limitations on object ownership and all the other mechanism to improve safety will impact day by day productivity and "flow".. at the moment, the °periodic table of pointer types" in Rust is not too promising :P


Stefano Casillo
Lead Programmer
TWITTER: @KunosStefano
AssettoCorsa - netKar PRO - Kunos Simulazioni

#13 kunos   Crossbones+   -  Reputation: 2207

Like
0Likes
Like

Posted 29 April 2014 - 05:35 PM

 

If you compare Go's performance with other garbage collected languages (C# on Mono, F# on Mono, Java, Scala, etc) in those benchmarks, you get pretty different results. With Mono based languages its mostly 50/50, whereas with JVM based languages it compares unfavorably on most cases.

 

 

true, but the good news is that Go is relatively speaking a very young language and it's closing that gap quickly with every new release as the focus is pretty much focused on performances right now. The JVM had had decades of man power dedicated to achieve the current level of performances.


Stefano Casillo
Lead Programmer
TWITTER: @KunosStefano
AssettoCorsa - netKar PRO - Kunos Simulazioni

#14 Promit   Moderators   -  Reputation: 7620

Like
6Likes
Like

Posted 29 April 2014 - 07:27 PM

The problem with GC in games isn't really performance, particularly for the indie crowd who are using those types of languages. At least, not directly. GC is plenty fast. What's lacking is control. The GC based languages are horrified that the application might want to exercise any kind of control or hinting about what to GC and when. I don't want random allocations to block and trigger GC. I want to be able to dispatch a bunch of GPU calls, then tell the runtime "hey, you've got 3ms to do as much incremental GC as you can". I want to be able to control the balance of GC time and convergence, and force full GC when required. I'd love to be able to tag objects explicitly with lifetime hints.

 

And frankly, I need to be able to rely on a consistent implementation underneath with known characteristics. I get why the language designers don't want this, but it's a huge practical problem for games. We NEED to be able to exercise real-time guarantees.


Edited by Promit, 29 April 2014 - 07:28 PM.


#15 kunos   Crossbones+   -  Reputation: 2207

Like
0Likes
Like

Posted 29 April 2014 - 08:27 PM

I want to be able to dispatch a bunch of GPU calls, then tell the runtime "hey, you've got 3ms to do as much incremental GC as you can".

 

ya I am always amazed at how this has never made into any language as far as I know.. that's EXACTLY what performance critical application need! it really looks like the perfect trade off between convenience of CG and performances. Treat the GC exactly as any other task (hopefully doable concurrently) that an app has to accomplish.

But, hey, what do I know? I make games and not compilers, I think (and hope) that there is a solid technical reason for not doing it this way.


Edited by kunos, 29 April 2014 - 08:28 PM.

Stefano Casillo
Lead Programmer
TWITTER: @KunosStefano
AssettoCorsa - netKar PRO - Kunos Simulazioni

#16 swiftcoder   Senior Moderators   -  Reputation: 10367

Like
1Likes
Like

Posted 29 April 2014 - 08:49 PM

What's lacking is control. The GC based languages are horrified that the application might want to exercise any kind of control or hinting about what to GC and when.

And it's not just about 'when' or 'how long', it's also about 'where'.

Cache coherency is a big issue, and if you can't control the layout of your memory allocations, your work is cut out for you. Try allocating a contiguous array of 4x4 matrices in Java, and you'll rapidly start tearing your hair...


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#17 Aldacron   GDNet+   -  Reputation: 3273

Like
0Likes
Like

Posted 30 April 2014 - 12:34 AM


My core problem with D in this respect is that it *is* just a C++ clone with some (but far from all) rough edges rounded off.
 
Sure it makes template metaprogramming simpler than C++, but it doesn't really add/enable a whole lot else. No native support for high concurrency, no attempt at a new memory model, no attempt to simplify or improve the basic programming model, and so forth...

 

All variables are thread-local by default; shared and immutable variables are the building blocks for concurrency and functional programming; library support for concurrency in the form of std.concurrency and std.parallelism; ranges (support both built-in and in the library); a growing subset of the language can be executed at compile time; compile-time and runtime introspection; template constraints; pluggable, component-based algorithms... I don't know when you last looked at it, but the D I know has got a bit more to it than C++. Though, it seems C++11 and C++14 have narrowed the gap. I expect that to continue with future versions of C++.



#18 SeraphLance   Members   -  Reputation: 1454

Like
0Likes
Like

Posted 30 April 2014 - 07:56 AM

The problem with GC in games isn't really performance, particularly for the indie crowd who are using those types of languages. At least, not directly. GC is plenty fast. What's lacking is control. The GC based languages are horrified that the application might want to exercise any kind of control or hinting about what to GC and when. I don't want random allocations to block and trigger GC. I want to be able to dispatch a bunch of GPU calls, then tell the runtime "hey, you've got 3ms to do as much incremental GC as you can". I want to be able to control the balance of GC time and convergence, and force full GC when required. I'd love to be able to tag objects explicitly with lifetime hints.

 

And frankly, I need to be able to rely on a consistent implementation underneath with known characteristics. I get why the language designers don't want this, but it's a huge practical problem for games. We NEED to be able to exercise real-time guarantees.

 

This is spot on.  It also makes me wonder if there is any research into timesliced GCs.  I'm not entirely sure if the productivity cost makes GCs even worth using at that point, but it does address the major sore in GCs in general, games or otherwise -- poor performance characteristics for real-time (hard or soft) applications.



#19 swiftcoder   Senior Moderators   -  Reputation: 10367

Like
0Likes
Like

Posted 30 April 2014 - 01:48 PM

This is spot on.  It also makes me wonder if there is any research into timesliced GCs.  I'm not entirely sure if the productivity cost makes GCs even worth using at that point, but it does address the major sore in GCs in general, games or otherwise -- poor performance characteristics for real-time (hard or soft) applications.

Real-time GCs are really not all that uncommon, they just aren't very widely used outside of fields requiring hard-realtime performance.

 

For example, see this article by IBM re Java.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#20 thok   Members   -  Reputation: 693

Like
0Likes
Like

Posted 01 May 2014 - 04:11 PM


There's nothing intrinsically wrong with it, but I personally don't like Go's hardline stance against generics

 

"This remains an open issue." is not a hardline stance. See http://golang.org/doc/faq#generics






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS