2026-05-12
Achieving Sub-Millisecond Routing in Go
Technical breakdown of zero-allocation HTTP router implementation.
The Allocation Problem
Standard HTTP routers in Go allocate memory on every request. At 50,000 requests per second, the garbage collector becomes the bottleneck — not your business logic.
Profiling a production service with pprof revealed that 40% of CPU time was spent in runtime.mallocgc. Each request triggered 7 heap allocations totaling ~1 KB.
The Zero-Allocation Approach
We implemented a radix trie that operates directly on the request byte slice:
- sync.Pool for reusable path buffers
- Stack-allocated parameter extraction
- Byte-slice matching — no string conversions
Results
| Metric | Before | After |
|---|---|---|
| Throughput | 5,000 rps | 50,000+ rps |
| Allocations | 1,024 B/op | 0 B/op |
| P99 Latency | 12ms | 0.8ms |
The key insight: eliminate allocations at the hot path, and the GC stops being your enemy.