LabscoMCP early access ↗

Which of Go's built-in containers to reach for — a slice, a map, a heap, a ring buffer — and what each one really costs in memory and copying.

WHEN TO USE

SCOPE

USE FOR

  • Preallocate a slice or map with make when the final size is already known.
  • Decide between container/list, container/heap, and container/ring for a specific job.
  • Pick strings.Builder over bytes.Buffer for pure string concatenation.
  • Write a generic collection type using the tightest constraint the case allows.
  • Use weak.Pointer for a cache that shouldn't stop the garbage collector from reclaiming entries.

NOT FOR

  • Not for applying optimization patterns once profiling has already found a bottleneck.