# Memory Experiment Loop — Go

Extends `../shared/experiment-loop-base.md` with Go memory-specific steps.

## Domain-Specific Additions

**Step 1 — Baseline profiling**: Run `go test -bench=. -memprofile=/tmp/mem.prof -benchmem -count=5` and save output to `/tmp/bench_baseline.txt`. Extract ranked allocators with `go tool pprof -top -alloc_space` and `-alloc_objects`. Also run escape analysis: `go build -gcflags='-m' 2>&1 | grep 'escapes to heap'`.

**Step 3 — Reasoning checklist**: Use the 8-question checklist from `codeflash-memory.md`.

**Step 9 — Benchmark**: Run `go test -bench=. -memprofile=/tmp/mem_after.prof -benchmem -count=5` and compare with `benchstat`. Focus on `B/op` and `allocs/op`.

**Step 10 — Guard**: Default guard: `go test -race -short ./...`.

**Step 12 — Re-profile (after KEEP)**: Re-run mem profile and escape analysis. Update baseline.

## Keep Thresholds

- **B/op**: ≥10% reduction with p < 0.05
- **allocs/op**: ≥10% reduction with p < 0.05
- **Escape count**: Reduction is a bonus metric
- **GC frequency**: Measurable reduction in `GODEBUG=gctrace=1` output

## Plateau

- All remaining allocators in runtime, stdlib, or third-party code
- Escape analysis shows no further reducible escapes
- 3+ consecutive discards across all allocation categories
