golang-data-structures

Optimize Go data structure choices and memory layout for slices, maps, arrays, and pointers.

2.9k|191|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/samber/cc-skills-golang --skill golang-data-structures
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-data-structures
Source: https://github.com/samber/cc-skills-golang/tree/main/skills/golang-data-structures
Command: npx skills add https://github.com/samber/cc-skills-golang --skill golang-data-structures

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go developers often struggle to choose and tune internal data structures. This skill explains the internals of slices, maps, arrays, and pointers, guiding decisions that impact memory usage and performance.

Core Features & Use Cases

  • Slice internals, capacity growth, preallocation, and the slices package (Go 1.21+).
  • Map internals, preallocation, and memory considerations for large collections.
  • Arrays, container/list vs slices for performance trade-offs, and copy semantics.
  • Pointer types including unsafe.Pointer and weak.Pointer for GC-safe caches.
  • Cross-references to related skills for safety, concurrency, and generics.

Quick Start

Audit your Go codebase using this skill to optimize memory layout by reviewing Slice Internals, Map Internals, and Pointer guidance.

Frequently Asked Questions about golang-data-structures

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do Go slice internals affect memory layout and capacity growth?

Go map internals use hash tables with buckets, and preallocating maps via make avoids rehashing overhead. For large collections, understanding memory layout and bucket distribution helps reduce allocation pressure in performance-critical Go systems.

What's the best way to optimize Go data structures for high-throughput systems?

Optimizing Go data structures requires auditing slices, maps, arrays, and pointers to tune memory layout. Use preallocation, the slices package (Go 1.21+), and container/list trade-offs to minimize allocations in performance-critical codebases.

When should I use unsafe.Pointer or weak.Pointer in Go for GC-safe caches?

Use unsafe.Pointer and weak.Pointer in Go for GC-safe caches when managing memory layout manually to avoid preventing garbage collection. These pointer types allow holding references without blocking GC, useful for memory-constrained high-throughput systems.

How do arrays and copy semantics differ from slices for Go performance?

Go arrays use value copy semantics, duplicating data on assignment, while slices reference a backing array. Arrays provide fixed memory layout, whereas slices offer dynamic capacity growth, making slices generally preferable for flexible Go data structures.

Does this guidance cover container/list vs slices for Go memory optimization?

Yes, this guidance compares container/list versus slices for Go memory optimization, evaluating performance trade-offs. Slices typically offer better memory layout and cache locality, while container/list suits specific insertion-heavy use cases in Go data structures.