4 ms·
Using sync.Pool for my personal projects has made them so much faster (/ use less heap) and let me retire my custom pools. So much awesome there. This presenta
by voidlogic 13y ago
Using sync.Pool for my personal projects has made them so much faster (/ use less heap) and let me retire my custom pools. So much awesome there.
This presentation also doesn't mention the concurrent GC sweep work: https://codereview.appspot.com/46430043/ https://codereview.appspot.com/46430043/
- 0xdeadbeefbabe 13y agohttp://talks.golang.org/2014/go1.3.slide#9 http://talks.golang.org/2014/go1.3.slide#9 Ok I see how it's go-routine (or thread) safe, but what is meant by "free list"? It's a pool of objects that you can access and put back, and putting back doesn't block? Free as in freeing memory maybe?
- joncooper 13y agoHere is an example from http.Transport: http://golang.org/src/pkg/net/http/transport.go#L408 http://golang.org/src/pkg/net/http/transport.go#L408 A connection pool is kept in the transport for use with HTTP keep-alive. When an http.Client makes a request using the transport, it tries to get an idle connection, failing that it starts creating a new connection. It then selects the first available connection, either the newly-dialed one, or one that becomes available in the pool. (If the latter case, it continues opening the new connection and then sticks it into the pool.)
- ominous_prime 13y agoA "free list" is a fairly standard programming pattern, though it's not as common to see now with memory management and GC in most languages. At the base level, all it is is a list of currently "free" (i.e. available) resources that have been pre-allocated.
- voidlogic 13y agoSometimes also referred to as an object pool. What makes this implementation special is that its pooling is both thread-local and global, and is plugged into the runtime/garbage collector. The former makes it much much faster than any pool the user could implement, and the later means is plays nice as resources become more scarce.
- wreegab 13y ago> not as common to see now with memory management and GC in most languages I actually have improved performance of js code significantly using pools to discard/reuse object instances in js.
- kinofcain 13y agothink of it as something like creating a pool using WeakReferences in java, you're telling the GC that it's ok to collect that object so you're not using up extra ram, but you still get the performance benefit of re-using objects. (Go's implementation is potentially more efficient as you're not creating the extra WeakReference<> object, as you would be in java).
- dvirsky 13y agoThe concurrent sweep thing is getting in? I sure hope so... I was disappointed not to see it there.