# Go Performance

> Optimización de rendimiento en Go. Usar al optimizar hot paths, reducir allocations, o mejorar latencia. Use when this capability is needed.

- Skill: `tomevault-io/go-performance` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/go-performance`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/go-performance/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/go-performance

---


# Skill: go-performance

Optimización de rendimiento en Go.

## Cuándo usar este skill

- Al optimizar hot paths
- Al reducir allocations
- Al mejorar latencia

## Principios

1. **Medir primero** con benchmarks
2. **Identificar hot paths**
3. **Optimizar solo lo necesario**

## Técnicas de Optimización

### Reducir Allocations

```go
// ❌ MAL
var results []Result
for _, item := range items {
    results = append(results, transform(item))
}

// ✅ BIEN: Pre-allocate
results := make([]Result, 0, len(items))
```

### Object Pooling

```go
var bufferPool = sync.Pool{
    New: func() interface{} { return new(bytes.Buffer) },
}

func process() {
    buf := bufferPool.Get().(*bytes.Buffer)
    defer func() { buf.Reset(); bufferPool.Put(buf) }()
    // usar buf...
}
```

### Caching

```go
type ExpressionCache struct {
    mu    sync.RWMutex
    cache map[string]*Expression
}

func (c *ExpressionCache) GetOrCompile(expr string) (*Expression, error) {
    // Fast path: lectura
    c.mu.RLock()
    if e, ok := c.cache[expr]; ok {
        c.mu.RUnlock()
        return e, nil
    }
    c.mu.RUnlock()
    // Slow path: compilar y guardar
}
```

## Benchmarks

```bash
go test -bench=. -benchmem ./...
go test -cpuprofile=cpu.prof -bench=BenchmarkX
go tool pprof cpu.prof
```

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/gofhir) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-13 -->

