News for hackers. Stuff that matters.
Re:Recycling memory buffers in Go by thirsteh on Monday August 26, 2013 @02:44PM (#6279021)
This is nice, but I can't help but feel it's a little wrong that we're still making free-lists like in the olden days.
Re:Recycling memory buffers in Go by tptacek on Monday August 26, 2013 @02:47PM (#6279050)
You absolutely don't need to do any of this to write Go programs that outperform Ruby or Python.
Re:Recycling memory buffers in Go by thirsteh on Monday August 26, 2013 @02:55PM (#6279110)
Generally, sure. But it's still pretty easy to write garbage-generating Go applications that exhaust memory because the GC isn't compacting. In some applications this is a nobrainer: use a free list. In some others, like when you don't actually know what kind of buffer size you'll need, it's not so easy (although you could argue you should just fixed-sized chunks for whatever you're doing, and recycle those, but that's a lot of work.)

What I'm saying boils down to: Free lists are definitely useful, but the GC could be better.

Re:Recycling memory buffers in Go by jbooth on Monday August 26, 2013 @03:07PM (#6279193)
"Could be better" is of course true for every single situation, no matter how good.

But even Java, which has what is generally regarded as the most advanced GC ever written, still has lots of applications doing the free-list of ByteBuffers or even better, the free-list of off-heap-allocated DirectByteBuffers which don't have to be moved during tenured generation compactions.

It seems pretty reasonable to me to have one or two freelists at the spots you're frequently allocating 64kb buffers, along with using the GC for the other 5,000 allocations in your project.

Re:Recycling memory buffers in Go by thirsteh on Monday August 26, 2013 @03:08PM (#6279202)
Sure. No disagreement.

Let me put it another way: Go's GC is still in its infancy compared to those in most other languages. It's perfectly fine to use, but there are some big things (e.g. no compaction) that stick out when using the language, whether you're working with free-lists or something else.

Re:Recycling memory buffers in Go by tptacek on Monday August 26, 2013 @03:16PM (#6279255)
I think you're going to find that even with no attention to allocation at all, your Golang programs are going to outperform their Ruby and Python equivalents.

That's a dicier assertion to make versus other languages, notably Java, but if you're coming to Golang from a high level language like Python, you're probably going to be happy with the performance you get out of naive code.

Re:Recycling memory buffers in Go by thirsteh on Monday August 26, 2013 @03:27PM (#6279324)
You're right (except for some cases like crypto and regex where other languages "cheat" by using C bindings or unstable versions), but that isn't where it has bit me. In general all my Go programs have been more than fast enough, but on several occasions I've had memory starvation problems that I would not be having in other languages (even if there is a way to do it without doing a lot of allocation and fragmentation in Go.)

I love Go, but "it's fast" isn't a good reason not to improve a subpar GC. (Which fortunately isn't a position the Go team is taking. I know everyone there would like to see a lot of interesting things happen with the GC. It just hasn't been one of the more pressing issues so far, and I've agreed. It's also a very difficult and "boring" thing to work on for most people, so it's not surprising that somebody hasn't just added an Azul C4-style concurrent GC in their spare time.)

Re:Recycling memory buffers in Go by pcwalton on Monday August 26, 2013 @09:18PM (#6280886)
Azul C4 requires a kernel module or a specialized kernel to support all the MMU tricks that it relies on to achieve maximum performance. I don't think it's really an appropriate choice for general purpose GC in a language that's designed to be easy to deploy.

Java HotSpot's collector makes the most sense IMHO: stop the world compacting in the young generation, mostly concurrent in the tenured generation. It achieves better throughput than Azul C4 too, according to the C4 paper.

Re:Recycling memory buffers in Go by agentS on Monday August 26, 2013 @10:16PM (#6281064)
I vaguely remember reading somewhere that they figured out a way to run their collector on stock Linux; I think the price they paid in exchange was (even) lower throughput (trying to track down reference so I know I wasn't daydreaming) (yes, I daydream about GCs).

A while ago, I read through the kernel patch they provided, and it was basically adding batch APIs for mremap so you don't have to have a TLB flush for every call. Also because all mutator threads needed to be paused at a safepoint while the remaps happen, so the batch API has much shorter pause time.

Re:Recycling memory buffers in Go by lucian1900 on Tuesday August 27, 2013 @04:52AM (#6282267)
Neither of HotSpot's collectors guarantee maximum latency, though, which is Azul C4's interesting feature.

I would pay throughput to achieve (soft) real-time GC.

Re:Recycling memory buffers in Go by stcredzero on Monday August 26, 2013 @09:55PM (#6281011)
> In general all my Go programs have been more than fast enough, but on several occasions I've had memory starvation problems that I would not be having in other languages

The problem with GC's languages, is that GC is "good enough" for prototyping and for undemanding stuff, but there are still these corner cases. Really, it's no different than other forms of memory management in this regard. It's just particularly beginner friendly.

Re:Recycling memory buffers in Go by aaronblohowiak on Monday August 26, 2013 @04:48PM (#6279831)
Yes, Golang is very young and its gc is one of the more 'immature' portions. However, in comparison to the tools that it is regularly displacing the overall speed is still a huge win. Eventually, Golang will get a better gc and in the meantime we can already enjoy faster programs. Nobody is arguing that the gc of today should be Golang's gc forever.
Re:Recycling memory buffers in Go by wglb on Monday August 26, 2013 @07:17PM (#6280531)
Have you noticed the starvation in 64 bit programs or 32 bit programs?
Re:Recycling memory buffers in Go by thirsteh on Monday August 26, 2013 @07:20PM (#6280538)
Both. They weren't issues with precision/no gc at all, but that the arena contents became fragmented, as far as I could tell.
Re:Recycling memory buffers in Go by cbhl on Monday August 26, 2013 @06:19PM (#6280274)
Just to clarify, by outperform, are you speaking wrt. memory usage?

If I recall correctly, there are still some very strong warnings against running Go on memory-constrained systems (< 1 GB).

Re:Recycling memory buffers in Go by bad_user on Tuesday August 27, 2013 @06:35AM (#6282586)
People pick Ruby and Python without having unrealistic expectations for performance and throughput. We already know their implementations suck and being the high-level languages that they are, we know how difficult they are to optimize.

However, if performance is a concern, then picking Go seems to me like quite a step back from say Ruby.

There are other alternatives as well, that are higher level and that are much better at performance than Ruby/Python. E.g. Java, C#, Scala, Clojure, Ocaml, Haskell.

Personally I love Scala and the JVM, but the one thing I don't like is the GC. The JVM has the best GCs ever, but sometimes you just want to do without one at all.

This is why I don't like Go. While it's a tasteful language, it's too low level, but it still depends on a GC (that's not precise, compacting or generational).

Mozilla's Rust is much more promising for me.

Re:Recycling memory buffers in Go by cmbaus on Monday August 26, 2013 @05:14PM (#6279958)
I agree, given the type of issues they are addressing (very high throughput application servers), I don't think a general purpose allocator (garbage collected or not) will ever get the performance they want. Recycling buffers is not a bad strategy for this type of application, no matter the language.
Re:Recycling memory buffers in Go by JulianMorrison on Monday August 26, 2013 @03:08PM (#6279197)
When malloc() has to deal with defragmenting allocations of varying length, I believe it does it by allocating from several pools each holding blocks of a fixed size, picking the smallest category that will fit. It wouldn't be hard to extend the buffered-channel technique to do this.
Re:Recycling memory buffers in Go by zwieback on Monday August 26, 2013 @03:25PM (#6279315)
The olden days are not that old. I find myself using static arrays, free lists, malloc and its OO brethren as well as GC when available. All of those things have been around for as long as I can remember.

It's nice not to have to worry about freeing allocated memory but if you write a lot of low-level code there's a certain level of unease about letting the language or OS take on something that can have such a large performance impact.