Zero heap allocation HTTP server using OxCaml. v experimental!
OCaml
125
39 commits
updated Jan 25, 2026
A high-performance HTTP/1.1 parser and serializer achieving zero heap
allocations using OxCaml's unboxed types (int16#, int64#, char#) and local allocations.
Will soon have io_uring on Linux.
int16# for offsets/counts and int64# for content lengths - no boxing overheadhttpz achieves zero-allocation parsing through:
#{...}): Request, span, and header types are stack-allocatedint16# for buffer offsets, int64# for content lengths, char# for byte comparisons@ local): Header list grows on the stack, not heapBenchmarks comparing httpz (OxCaml) vs httpe (Eio-based parser):
| Request Size | httpz (ns/op) | httpe (ns/op) | Speedup | Allocation Reduction |
|---|---|---|---|---|
| Small (35B) | 154 | 159 | 1.03x | 45x fewer words |
| Medium (439B) | 1,150 | 1,218 | 1.06x | 399x fewer words |
| Large (1155B) | 2,762 | 2,912 | 1.05x | 823x fewer words |
Throughput: 6.5M requests/sec
| Operation | Time | Heap Allocations |
|---|---|---|
| Parse minimal request (35B) | 300ns | 0 words |
| Parse simple request (4 headers) | 925ns | 0 words |
| Parse browser request (10 headers) | 3.3μs | 0 words |
| Parse 50 headers | 11.2μs | 0 words |
| Write status line | 76ns | 0 words |
| Write full response headers | 454ns | 0 words |
True zero-allocation parsing - all values are stack-allocated via unboxed records and threaded position.
Requires OxCaml compiler from https://oxcaml.org/
An Async-based static file server is included:
# Serve current directory on port 8080
dune exec bin/httpz_server.exe
# Serve specific directory on custom port
dune exec bin/httpz_server.exe -- -d /var/www -p 3000
# Get help
dune exec bin/httpz_server.exe -- -help
Features:
index.html for directories# Comparative benchmark (httpz vs httpe)
dune exec bench/bench_compare.exe
# Detailed httpz benchmarks with core_bench
dune exec bench/bench_httpz.exe -- -quota 2
ISC
39 commits
OCaml
99.6%
Zero heap allocation HTTP server using OxCaml. v experimental!
OCaml
125
39 commits
updated Jan 25, 2026
A high-performance HTTP/1.1 parser and serializer achieving zero heap
allocations using OxCaml's unboxed types (int16#, int64#, char#) and local allocations.
Will soon have io_uring on Linux.
int16# for offsets/counts and int64# for content lengths - no boxing overheadhttpz achieves zero-allocation parsing through:
#{...}): Request, span, and header types are stack-allocatedint16# for buffer offsets, int64# for content lengths, char# for byte comparisons@ local): Header list grows on the stack, not heapBenchmarks comparing httpz (OxCaml) vs httpe (Eio-based parser):
| Request Size | httpz (ns/op) | httpe (ns/op) | Speedup | Allocation Reduction |
|---|---|---|---|---|
| Small (35B) | 154 | 159 | 1.03x | 45x fewer words |
| Medium (439B) | 1,150 | 1,218 | 1.06x | 399x fewer words |
| Large (1155B) | 2,762 | 2,912 | 1.05x | 823x fewer words |
Throughput: 6.5M requests/sec
| Operation | Time | Heap Allocations |
|---|---|---|
| Parse minimal request (35B) | 300ns | 0 words |
| Parse simple request (4 headers) | 925ns | 0 words |
| Parse browser request (10 headers) | 3.3μs | 0 words |
| Parse 50 headers | 11.2μs | 0 words |
| Write status line | 76ns | 0 words |
| Write full response headers | 454ns | 0 words |
True zero-allocation parsing - all values are stack-allocated via unboxed records and threaded position.
Requires OxCaml compiler from https://oxcaml.org/
An Async-based static file server is included:
# Serve current directory on port 8080
dune exec bin/httpz_server.exe
# Serve specific directory on custom port
dune exec bin/httpz_server.exe -- -d /var/www -p 3000
# Get help
dune exec bin/httpz_server.exe -- -help
Features:
index.html for directories# Comparative benchmark (httpz vs httpe)
dune exec bench/bench_compare.exe
# Detailed httpz benchmarks with core_bench
dune exec bench/bench_httpz.exe -- -quota 2
ISC
39 commits
OCaml
99.6%