-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
Description
Many Go programs and packages try to reuse memory either for locality reasons or to reduce GC pressure: pkg/regexp: pool of available threads pkg/net/http: wants to reuse a lot and has TODOs, but has resisted the temptation so far pkg/fmt: print.go's var ppFree = newCache(func() interface{} { return new(pp) }) pkg/io: for the 32 KB copy buffers; see discussion at https://golang.org/cl/7206048/ (which spawned this bug). These buffers showed up in dl.google.com profiles. Lot of things in the Go standard library use io.Copy, so this can't be fixed by caller code. pkg/io/ioutil: see https://code.google.com/p/go/source/browse/src/pkg/io/ioutil/blackhole.go for reusing the Discard buffers dl.google.com: was allocating hundreds of MB/s, causing lots of GCs, until we added a google-internal (for now) []byte pool reuse library, with an API like: package pool func NewBytePool(...opts...) *BytePool func (*BytePool) Alloc(n int) []byte func (*BytePool) Free(buf []byte) There are two distinct but related uses: * reusing small-ish structs (like regexp, fmt) * reusing bigger []byte (io, ioutil, dl.google.com) The former would benefit more from a per-m cache. Dmitry and Russ had some thoughts towards this. With big []byte, per-m doesn't matter as much, but you do care about things not being able to burst to some threshold (yet not retain memory for too long unnecessarily) and grouping things into size classes (i.e. a "user-space" tcmalloc) when the sizes differ. The question: Do we make a new package or facility to promote this pattern? The status quo is that it keeps being reimplemented in each package privately, and poorly. It'd be nice to have a good implementation that everybody could reuse. Almost all uses are beyond what I believe are reasonable with static liveness/escape analysis. This isn't a GC problem, because by the time the GC's involved, it's too late and we've already allocated too much. This is about allocating less and reusing memory when caller code knows it's no longer needed.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
rsc commentedon Jan 29, 2013
Comment 1:
Labels changed: added priority-later, go1.1maybe, removed priority-triage, go1.1.
Status changed to Thinking.
gopherbot commentedon Jan 31, 2013
Comment 2 by jgrahamc:
dvyukov commentedon Feb 1, 2013
Comment 3:
dvyukov commentedon Feb 1, 2013
Comment 4:
dvyukov commentedon Feb 1, 2013
Comment 5:
bradfitz commentedon Feb 1, 2013
Comment 6:
dvyukov commentedon Feb 3, 2013
Comment 7:
bradfitz commentedon Feb 3, 2013
Comment 8:
rsc commentedon Feb 3, 2013
Comment 9:
robpike commentedon Mar 7, 2013
Comment 10:
Labels changed: removed go1.1maybe.
dvyukov commentedon Mar 10, 2013
Comment 11:
rsc commentedon Mar 11, 2013
Comment 12:
bradfitz commentedon Mar 11, 2013
Comment 13:
rsc commentedon Mar 11, 2013
Comment 14:
alberts commentedon Mar 11, 2013
Comment 15:
15 remaining items
bradfitz commentedon Dec 18, 2013
Comment 31:
This issue was updated by revision 0f93118.
bradfitz commentedon Dec 18, 2013
Comment 32:
This issue was updated by revision 46b4ed2.
bradfitz commentedon Dec 18, 2013
Comment 33:
This issue was updated by revision 93e4a9d.
bradfitz commentedon Dec 19, 2013
Comment 34:
This issue was updated by revision b682f6d.
bradfitz commentedon Jan 6, 2014
Comment 35:
This issue was updated by revision 90e9669.
rsc commentedon Apr 2, 2014
Comment 36:
Status changed to Fixed.
gopherbot commentedon Apr 28, 2015
CL https://golang.org/cl/8202 mentions this issue.
cmd/internal/gc: improve flow of input params to output params