Go performance optimizations including memory allocation reduction, efficient string building, I/O operations, and resource pooling. Use when optimizing Go code for speed or memory efficiency.
Provides Go performance optimization guidance for memory allocation reduction, efficient string building, I/O operations, and resource pooling. Use when optimizing Go code for speed or memory efficiency.
/plugin marketplace add jovermier/cc-stack-marketplace/plugin install cc-go@cc-stack-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/allocations.mdreferences/benchmarking.mdreferences/io.mdreferences/strings.mdExpert guidance for writing efficient, high-performance Go code.
| Concern | Solution | Impact |
|---|---|---|
| String concatenation in loops | strings.Builder | O(n) vs O(n²) |
| Repeated allocations | sync.Pool | Reduces GC pressure |
| Large byte slice to string conversion | unsafe package (carefully) | Avoids allocation |
| I/O operations | bufio.Scanner/buffered writers | Reduces syscalls |
| Defer in tight loops | Move defer outside function | Prevents memory buildup |
| Premature optimization | Don't do it | Measure first |
Specify a number or describe your performance concern.
| Response | Reference to Read |
|---|---|
| 1, "string", "concat", "build" | strings.md |
| 2, "allocation", "memory", "pool" | allocations.md |
| 3, "io", "file", "reader", "writer" | io.md |
| 4, "benchmark", "measure", "profile" | benchmarking.md |
| 5, general performance | Read relevant references |
| Issue | Performance Cost | Fix |
|---|---|---|
| String + in loop | O(n²) allocations | strings.Builder |
| Defer in loop | Unbounded memory | Move to separate function |
| Byte to string conversion | Allocates new string | unsafe.String (careful) |
| Unbuffered I/O | System call per byte | bufio.Reader/Writer |
| Repeated allocations | High GC pressure | sync.Pool |
| Substring allocations | O(n) per operation | Use []byte views |
// Bad: O(n²) allocations
func build(items []string) string {
var s string
for _, item := range items {
s += item + "," // New string each iteration
}
return s
}
// Good: O(n) with pre-allocation
func build(items []string) string {
var b strings.Builder
b.Grow(len(items) * 10) // Pre-allocate if you can estimate
for _, item := range items {
b.WriteString(item)
b.WriteByte(',')
}
return b.String()
}
// Bad: Defers accumulate until function returns
func process(files []string) error {
for _, f := range files {
file, err := os.Open(f)
if err != nil {
return err
}
defer file.Close() // BAD: All deferred until return!
}
return nil
}
// Good: Each defer released when function returns
func process(files []string) error {
for _, f := range files {
if err := processFile(f); err != nil {
return err
}
}
return nil
}
func processFile(path string) error {
file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close() // GOOD: Released when processFile returns
// ...
return nil
}
var bufferPool = sync.Pool{
New: func() interface{} {
return new(bytes.Buffer)
},
}
func getBuffer() *bytes.Buffer {
return bufferPool.Get().(*bytes.Buffer)
}
func putBuffer(b *bytes.Buffer) {
b.Reset()
bufferPool.Put(b)
}
| File | Topics |
|---|---|
| strings.md | Builder, Reader, efficient concatenation |
| allocations.md | sync.Pool, escape analysis, reduction strategies |
| io.md | bufio, Scanner, buffered writers, chunking |
| benchmarking.md | Writing benchmarks, pprof, flame graphs |
Code is performant when:
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.