Go Perf Slices

Guides Go slice performance beyond correctness — the real growslice factors (2x while cap less than 256, then newcap += (newcap+768) greater than greater than 2 ≈ 1.25x), preallocating via make([]T, 0, n) and slices.Grow to avoid repeated grow-and-copy, reusing buffers with b = b[:0], copy vs append, the GC-scan cost of []*T, slices.Clip, and a subslice pinning a huge backing array. Fires on "preallocate this slice", "why is append slow", "reduce slice allocations", "reuse this buffer". Routes aliasing to go-slices-and-maps, layout to go-perf-data-oriented-layout.

ctoth bd4f82f 3 files · 23.9 KB Updated

File contents

ctoth/golang-skills-plugin/tree/main/plugins/performant-golang/skills/go-perf-slices commit bd4f82fda4

Frequently asked questions

npx skillmds@latest add ctoth/go-perf-slices