When you drink a soda, do you recycle the can? When you allocate a slice, do you recycle the memory? Recycling cans is good for the planet and recycling slices can be good for your Go program. But how? The garbage collector? A sync.Pool? Something else? You’ll be surprised what a difference it makes!
54. 1. ‘null’ – use the garbage collector
2. ‘sync’ – use a sync.Pool
55. 1. ‘null’ – use the garbage collector
2. ‘sync’ – use a sync.Pool
3. ‘power2’ – sync.Pool per size bucket
56. 1. ‘null’ – use the garbage collector
2. ‘sync’ – use a sync.Pool
3. ‘power2’ – sync.Pool per size bucket
4. ‘reserved’ – keep N buffers around forever
90. 1. ‘null’ – use the garbage collector
2. ‘sync’ – use a sync.Pool
3. ‘power2’ – sync.Pool per size bucket
4. ‘reserved’ – keep N buffers around forever
93. Workload
• N items to encode
• 20 goroutines encoding
• Up to 1000 keys per encoding
• Up to 200 characters per key
94. Isolation
• Pre-generate random data lists outside loops
• Turn on profiler after data generation
• Constant randSeed for repeatability
• Goroutines iterate data lists from random
starting points
• Profile/trace with standalone executable