←back to thread

480 points jedeusus | 1 comments | | HN request time: 0.202s | source
Show context
nopurpose ◴[] No.43540684[source]
Every perf guide recommends to minimize allocations to reduce GC times, but if you look at pprof of a Go app, GC mark phase is what takes time, not GC sweep. GC mark always starts with known live roots (goroutine stacks, globals, etc) and traverse references from there colouring every pointer. To minimize GC time it is best to avoid _long living_ allocations. Short lived allocations, those which GC mark phase will never reach, has almost neglible effect on GC times.

Allocations of any kind have an effect on triggering GC earlier, but in real apps it is almost hopeless to avoid GC, except for very carefully written programs with no dependenciesm, and if GC happens, then reducing GC mark times gives bigger bang for the buck.

replies(12): >>43540741 #>>43541092 #>>43541624 #>>43542081 #>>43542158 #>>43542596 #>>43543008 #>>43544950 #>>43545084 #>>43545500 #>>43551041 #>>43551691 #
Capricorn2481 ◴[] No.43541092[source]
Aren't allocations themselves pretty expensive regardless of GC?
replies(2): >>43541302 #>>43541882 #
epcoa ◴[] No.43541882[source]
No. If you have a moving multi generational GC, allocation is literally just an increment for short lived objects.
replies(3): >>43542264 #>>43542385 #>>43542676 #
pebal ◴[] No.43542676[source]
If you have a moving, generational GC, then all the benefits of fast allocation are lost due to data moving and costly memory barriers.
replies(3): >>43543435 #>>43544627 #>>43551434 #
1. ◴[] No.43543435[source]