by VeejayRampay · 12y ago · 0 comments
Absolutely, but it's not a reason to not use Go. The web is probably the platform with the least possible damage caused by GC.
It's OK if people like the language and want to use it for web development, though. I'm personally pretty excited about it, because I'm not a huge fan of Go and Rust looks pretty neat.
My experience has been that Go has very lightweight GC. The compiler intelligently turns a significant number of allocations into stack allocations (the same allocations would be heap allocations in .NET and Java, by comparison). It, by design, minimizes the amount of work that the GC needs to do, and in most real projects it just becomes a complete non-issue.
There are many domains in which GC is a deal-breaker, simply because you lose the fine-grained control over memory that you require: for example, games, embedded systems, kernels, and browser engines. (Go does not give you control over memory in the same way that C++, for example, does; consider map elements or closure upvars.)
> The compiler intelligently turns a significant number of allocations into stack allocations (the same allocations would be heap allocations in .NET and Java, by comparison).
No, .NET and Java do escape analysis as well.
The difference is that the JVM and CLR have generational garbage collectors with a copying nursery, so heap allocations are essentially as cheap as stack allocations: just a pointer bump. In the JVM (in contrast to Go) escape analysis is mainly used for eliding locks; allocation is so cheap that promoting heap allocations to stack allocations barely matters.
Sure. That encompasses a very small set of code. Indeed, it's interesting that you mentioned games given that most game engines now are a relatively small non-GC engine, layered atop with GC technologies.
You are a rather heavy advocate of Rust, and for whatever bizarre reason the Rust crew has decided that they need to aggressively attack Go (I'd recommend you maybe focus on delivering a production product first?), but it's interesting that you did exactly what I said -- it's just a checkmark.
"GC baaaaaaad".
Having developed a number of solutions with Go, and been involved in the solutions of others, interestingly the GC has never -- literally never -- been an issue with the platform. It has never, once, come up as a weakness with the language.
Now I'm not using Go to make a real-time nuclear power plant controller, nor would I ever use Rust for that.
No, .NET and Java do escape analysis as well.
.NET does not do escape analysis: Every reference allocation starts as a generation 0 heap allocation, and every collection is just as complex as any GC collection. Java mostly performs it for, as you mention, lock eliding.
so heap allocations are essentially as cheap as stack allocations: just a pointer bump
When comparing stack versus GC heap, the allocation is irrelevant. It's the clean-up that is the difference: The fundamental mechanism of how GC works guarantees it cannot possibly even come remotely close to approaching the speed of stack freeing.
And
"The current implementation is a parallel mark-and-sweep collector but a future version might take a different approach." (which I'm certain it will)
That's true (although I would question the use of "allocation" there—I think Java has as much control over when you allocate as Go does), but "some control" is not always enough control.
Have you done a back of the envelope calculation to justify this? I have a Javascript/browser MMO engine backend that's written in Go. I simply invoke the garbage collector every world-tick (8 times a second) and that works great for me. I can manage a huge world with GC pauses as large as 20ms.