Re:Show HN: Strife, a 2D game library for Go
by nullstyle on Saturday September 29, 2018 @01:22PM
(#18101574)
It seems to me that you're not really taking a charitable interpretation of GP's comment. For example, in my game development experience (granted, I'm 6 years removed from that industry) we often relied on object pools to avoid allocation. You don't need to know anything about Go's escape analysis to use a pool to avoid allocation, as far as I can tell. Could you explain your position further?
Re:Show HN: Strife, a 2D game library for Go
by pcwalton on Saturday September 29, 2018 @02:34PM
(#18101986)
Go language constructs allocate in ways that are not immediately obvious. So using object pools is not sufficient to avoid allocation in Go as compared to, say, C++.
In my view (which is the dominant view among compiler engineers for GC'd languages), spending a lot of effort to avoid allocation is a poor use of programmer time in a GC'd language. It is better to just improve the GC to make allocation fast. In a properly designed generational GC like that of Java HotSpot, allocation is about 5 instructions. That is a game changer: allocation is as cheap as a function call plus the prologue.
Unfortunately, Go's designers have so far not deployed generational GC, which is why we keep having these threads about avoiding allocation. (I've seen indications in the last couple of weeks that Go may finally be moving to a generational GC, though, and I hope they do.)
Re:Show HN: Strife, a 2D game library for Go
by pjmlp on Saturday September 29, 2018 @02:28PM
(#18101949)
Anyone doing HTML 5/Flash like games in Go doesn't need to worry like if they are writting the next Fortnight in Vulkan.
Re:Show HN: Strife, a 2D game library for Go
by pcwalton on Saturday September 29, 2018 @02:42PM
(#18102020)
This is why I've been careful to say "CPU-intensive workloads" and not "games", because not all games are CPU-intensive workloads.
Re:Show HN: Strife, a 2D game library for Go
by nullstyle on Saturday September 29, 2018 @04:11PM
(#18102533)
You weren't careful to say it in this subthread though. I had a whole response written up to talk about how you're being completely unreasonable with regards to most gaming projects before I saw this clarification. Now all that effort is wasted! ;)
Re:Show HN: Strife, a 2D game library for Go
by pjmlp on Saturday September 29, 2018 @03:16PM
(#18102240)
Ah, sorry I missed it.
Then I fully agree with you.
Re:Show HN: Strife, a 2D game library for Go
by weberc2 on Saturday September 29, 2018 @08:23PM
(#18103811)
You’re splitting hairs. Yes, you need to reason about escape analysis. This is pretty easy, especially since the compiler will tell you when things escape. It’s certainly easier than... well, pretty much anything in C++. :)
As a practical example, capturing variables in a closure will usually cause them to be heap allocated in Go, but in C++ capturing has no effect on variable storage.