golang-data-structures

Selects and optimizes Go data structures based on slice and map memory behavior.

4|Updated May 17, 2026
One-click install
npx skills add https://github.com/hellopoisonx/aim --skill golang-data-structures-hellopoisonx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-data-structures
Source: https://github.com/hellopoisonx/aim/tree/main/skills/golang-data-structures
Command: npx skills add https://github.com/hellopoisonx/aim --skill golang-data-structures-hellopoisonx

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you avoid performance and correctness bugs when selecting and optimizing Go data structures by explaining how slices and maps actually behave in memory.

Core Features & Use Cases

  • Practical slice and map internals: Understand slice headers, capacity growth, backing-array aliasing, and map bucket/overflow behavior to predict allocation and performance.
  • Safe optimization guidance: Learn when to preallocate, when to use standard containers like container/list and container/heap, and how to prevent common pitfalls (nil maps, append aliasing, defensive copying).
  • Type- and GC-aware design: Apply generics constraints correctly for sets and ordered collections, and use pointers (including unsafe.Pointer patterns and weak.Pointer) with guardrails.
  • Use case: When building a high-throughput in-memory cache or scheduler, design the right key types, avoid accidental sharing between slices, and ensure efficient priority operations using the appropriate stdlib container.

Quick Start

Use the golang-data-structures skill to choose the optimal Go data structures for your cache/scheduler workload and to rewrite your current slice/map logic to eliminate aliasing and unnecessary allocations.

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 memory internals affect capacity growth and backing-array aliasing?

Go slice memory internals dictate that capacity growth reallocates the backing array, causing unexpected aliasing if multiple slices share it. Understanding this behavior helps predict allocation costs and prevents accidental data sharing in high-throughput paths.

How do I prevent nil map panics and append aliasing when building Go caches?

To prevent nil map panics and append aliasing in Go caches, you must initialize maps before writes and apply defensive copying. This ensures correct access patterns and avoids accidental memory sharing during concurrent operations.

What is the best way to apply generics constraints for Go sets and ordered collections?

The best way to apply generics constraints for Go sets and ordered collections is using type parameters with comparable interfaces. This enables type-safe, GC-aware design while ensuring efficient priority operations using appropriate stdlib containers.

When should I use unsafe.Pointer and weak.Pointer patterns in Go schedulers?

Use unsafe.Pointer and weak.Pointer patterns in Go schedulers only when managing memory internals directly to avoid allocation overhead. Apply strict safety guardrails to prevent pointer corruption and ensure correct garbage collection behavior.

Does the Go container/heap or container/list stdlib support high-throughput priority queues?

Yes, the Go container/heap and container/list stdlib packages support high-throughput priority queues by providing standard container implementations. They allow efficient priority operations without custom allocations when selected correctly.