Skip to main content

Performance

Benchmark Results

Apple M4 / darwin arm64 / Go 1.22+ / 0 allocs across all tests.

Single Writer

ScenarioseqflowchannelSpeedup
1 slot per op2.1 ns21 ns10x
16 slots per op0.14 ns22 ns/msg160x

Multi Writer (4 goroutines)

ScenarioseqflowchannelSpeedup
1 slot per op39 ns100 ns2.6x
16 slots per op2.3 ns103 ns/msg45x

Why is batch so fast?

Reserve(16) claims 16 slots with a single atomic operation. Channel must send 16 times, each with a lock acquisition.

Running Benchmarks

# All benchmarks
go test -bench=. -benchmem -count=3 -timeout 120s

# Single writer only
go test -bench=BenchmarkSeqflow_SingleWriter -benchmem

# WaitStrategy comparison
go test -bench=BenchmarkWaitStrategy -benchmem

# DAG topology
go test -bench=BenchmarkDAG -benchmem

Design Optimizations

  1. Pre-computed remaining capacity — fast path: 1 comparison instead of subtraction + 2 comparisons
  2. Zero interface dispatch — single-writer fields embedded directly in Disruptor struct
  3. Zero atomic loads on fast path — Close poisons capacity counter
  4. Pre-dereferenced commit pointer — eliminates pointer chasing in Commit
  5. Cache-line padding — atomic sequences aligned to CPU cache lines, prevents false sharing