3 ms·
The main way to really reduce GC pressure in a fully GC'd system, short of improving the GC itself, is to use pooling. It occurs to me, that I don't understand
by stcredzero 13y ago
The main way to really reduce GC pressure in a fully GC'd system, short of improving the GC itself, is to use pooling.
It occurs to me, that I don't understand how pooling helps a non generational GC like golang's. In a generational collector, the contents of the pool would be promoted to regions of GC memory that are copied less. Go's GC isn't generational, so what is going on?
- pcwalton 13y agoIf you use a pool, you can explicitly return memory to it without going through the GC. This causes mark/sweep cycles to occur less often. (Of course, using pools opens you up to use-after-free and memory leaks, albeit without the type- and memory-safety consequences of use-after-free in C/C++.)
- stcredzero 13y agoIf you use a pool, you can explicitly return memory to it without going through the GC. This causes mark/sweep cycles to occur less often. In a non-generational collector, why less often? Is it that the GC "sees" less garbage, and this figures into the frequency of mark/sweep cycles? EDIT: Okay, I just got it. If you assume it's a bump allocator, it's easiest to picture. So Go does have another big advantage with regards to reducing GC pressure, in that one can stack allocate structs and arrays. (One would be passing slices on those arrays most often, and stack allocated would be slightly less flexible, of course.)
- pcwalton 13y agoRight. See the documentation here [1]. Typically GCs run on allocation when they see a high ratio of the live set from the previous run to total memory in use. [1]: http://golang.org/pkg/runtime/debug/#SetGCPercent http://golang.org/pkg/runtime/debug/#SetGCPercent