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:

  1. sync.Pool for reusable path buffers
  2. Stack-allocated parameter extraction
  3. Byte-slice matching — no string conversions

Results

MetricBeforeAfter
Throughput5,000 rps50,000+ rps
Allocations1,024 B/op0 B/op
P99 Latency12ms0.8ms

The key insight: eliminate allocations at the hot path, and the GC stops being your enemy.

AJ

Distributed Systems & AI Infrastructure

© 2026 ALIREZA JAFARTASHBUILT WITH PRECISION · REV. 2026.06