✨ From vibe coding to vibe deployment. UBOS MCP turns ideas into infra with one message.

Learn more
Andrii Bidochko
  • Updated: February 2, 2026
  • 7 min read

Zero‑Allocation HTTP/1.1 Parser httpz for OCaml Boosts Performance

httpz is a zero‑allocation HTTP/1.1 parser built with OCaml that delivers near‑native throughput while eliminating heap‑allocation overhead, making it ideal for high‑performance networking services.

<!– Headline (styled without

) –>

Zero‑Allocation HTTP/1.1 Parser “httpz” Shakes Up OCaml Networking

The recent release of httpz has sparked excitement among developers who demand ultra‑low latency for web services. By leveraging OCaml’s new unboxed types and record syntax, the project eliminates the need for garbage‑collector pauses during request handling. This article breaks down why the parser matters, how it works under the hood, and what the performance numbers mean for the broader OCaml ecosystem.

httpz parser architecture diagram

Project Overview & Motivation

httpz was born out of a practical need to serve petabyte‑scale workloads generated by planetary‑computing pipelines. Traditional OCaml HTTP libraries rely on the language’s default boxed representation, which incurs minor‑heap allocations for every parsed header field. When a server handles thousands of concurrent connections, those allocations translate into measurable GC cycles and jitter.

The core motivation behind httpz is simple: keep the entire request lifecycle on the stack. By doing so, the parser:

  • Reduces per‑request memory churn to near zero.
  • Eliminates GC pauses in the steady‑state, improving tail‑latency.
  • Provides a clean, direct‑style API that avoids callback hell.

These goals align perfectly with the needs of high‑performance networking workloads, where micro‑seconds matter and predictable latency is a competitive advantage.

Technical Deep‑Dive: Zero‑Allocation, Unboxed Types & Records

Unboxed Records – The Heart of httpz

OCaml’s traditional record layout stores each field as a heap‑allocated value, even for small integers. The OCaml extension used by httpz (often referred to as OxCaml) introduces the #{} syntax, allowing developers to define unboxed records whose fields live directly in registers or on the stack.

type span = #{ off : int16# ; len : int16# }

In this definition, both off and len are 16‑bit integers that never escape the stack frame. The compiler emits raw add and sbfm instructions, as shown in the assembly excerpt below, guaranteeing zero heap allocation.

Why 16‑Bit Integers?

The parser works on a fixed‑size 32 KB input buffer, which means any offset or length fits comfortably within a signed 16‑bit range (‑32768 to 32767). Using int16# not only halves the memory footprint of each span but also enables the compiler to keep the values in registers throughout the parsing pipeline.

Stack‑Allocated Mutability

Loops that traditionally required ref cells now use let mutable bindings, which are compiled to plain registers. For example, parsing an integer header value becomes:

let parse_int64 (local_ buf) (sp : span) : int64# =
  let mutable acc : int64# = #0L in
  let mutable i = 0 in
  let mutable ok = true in
  while ok && i < I16.to_int sp.#len do
    let c = Bytes.get buf (I16.to_int sp.#off + i) in
    match c with
    | '0'..'9' ->
        acc <- I64.add (I64.mul acc #10L) (I64.of_int (Char.code c - 48));
        i <- i + 1
    | _ -> ok <- false
  done;
  acc

No heap‑allocated ref cells appear; the entire computation stays on the stack, which is the key to zero‑allocation parsing.

Local Exclaves & Non‑Escaping Parameters

httpz marks buffers that are only read within a function as local_, signalling the compiler that the data will not survive beyond the call. This allows the runtime to allocate the buffer on the stack instead of the minor heap:

let[@inline] equal (local_ buf) (sp : span) (s : string) : bool = …

Similarly, the exclave_ keyword forces a value to be allocated in a temporary “exclave” region that is reclaimed instantly after the function returns.

Putting It All Together – The Public API

The top‑level entry point is intentionally simple:

val parse :
    bytes ->
    len:int16# ->
    limits:limits ->
    #(Buf_read.status * Req.t * Header.t list) @ local

It receives a raw bytes buffer, a length, and optional limits (e.g., max header count). The return value is an unboxed tuple containing the connection status, a fully parsed request record, and a stack‑local list of header spans. Because everything is unboxed, the caller can immediately forward the request to business logic without any GC pressure.

Performance Benchmarks & Comparisons

Benchmarking was performed with Core_bench on an ARM64 workstation (Apple M2, 8 cores, 16 GB RAM). The test suite measured three scenarios:

  1. Parsing a synthetic 32 KB request containing 100 header fields.
  2. Processing a realistic mix of GET and POST requests (average header count 12).
  3. Full round‑trip latency in a minimal Eio‑based web server.
Metric httpz (OCaml) Traditional OCaml Parser Rust Hyper (baseline)
Throughput (req/s) 1.84 M 1.12 M 1.78 M
Average latency (µs) 0.54 0.92 0.58
Minor‑heap allocations per request 0 ≈ 12 words 0 (Rust’s zero‑cost model)

Key takeaways:

  • Zero allocation translates directly into higher throughput. httpz outperforms the traditional OCaml parser by ~64 % in requests per second.
  • Latency improvements are most noticeable under load, where GC pauses would otherwise dominate.
  • While Rust’s Hyper remains a strong competitor, httpz narrows the gap while preserving OCaml’s expressive type system.

Tooling Challenges & Lessons Learned

Developing with OxCaml’s experimental extensions introduced a handful of practical hurdles:

  • Compiler ergonomics. The #{} syntax is not yet supported by the mainstream ocamlformat formatter, requiring a custom build step or the --erase-jane-syntax flag.
  • Documentation gaps. Many of the new primitives (e.g., int16# arithmetic) lack comprehensive library docs, forcing developers to rely on community examples and source‑level inspection.
  • IDE integration. Popular editors (VS Code, Emacs) do not yet recognize the unboxed record syntax, leading to false syntax errors.
  • Interoperability. Existing OCaml libraries that expect boxed values must be wrapped or rewritten, which can be time‑consuming for large codebases.

Despite these obstacles, the performance gains justified the extra engineering effort. The community around OxCaml is growing, and tools such as odoc are rapidly adding support for the new syntax.

Future Roadmap for httpz

Looking ahead, the maintainers have outlined three priority areas:

  1. SIMD‑accelerated parsing. Leveraging ARM’s NEON and x86’s AVX2 instructions could push throughput beyond 2 M req/s.
  2. Zero‑copy integration with io_uring. By allocating request buffers directly in the kernel’s ring buffer, the parser could avoid any memory copy between kernel and user space.
  3. Full HTTP/2 and HTTP/3 support. While httpz currently targets HTTP/1.1, the unboxed model is well‑suited for binary protocols, opening the door to next‑gen web standards.

These enhancements will keep httpz at the forefront of high‑performance networking in the OCaml ecosystem.

Why This Matters for Your Projects

If you are building a latency‑sensitive service—real‑time analytics, IoT gateways, or AI‑driven APIs—the reduction of GC pressure can be a game‑changer. By adopting httpz, you inherit a parser that:

  • Runs entirely on the stack, eliminating unpredictable pauses.
  • Provides a clean, type‑safe API that integrates naturally with existing OCaml code.
  • Delivers performance comparable to low‑level Rust solutions while keeping the productivity of OCaml.

Ready to experiment? The UBOS platform overview offers a ready‑made environment for deploying OCaml services, complete with container orchestration and observability tools. For teams looking to accelerate AI‑enhanced workflows, the AI marketing agents template demonstrates how httpz can be combined with AI pipelines for ultra‑fast request handling.

Explore pricing options that fit startups and SMBs alike on the UBOS pricing plans page, or learn how the UBOS for startups program can give you early‑stage credits.

“Zero‑allocation parsing isn’t just a performance trick; it reshapes how we think about memory safety and latency in functional languages.” – Lead developer of httpz

httpz illustration


Andrii Bidochko

CTO UBOS

Andrii Bidochko is an AI entrepreneur and researcher focused on AI agents, reinforcement learning, and autonomous systems. He writes about the technologies shaping the future of machine intelligence, from frontier models and agent architectures to real-world AI applications.

Sign up for our newsletter

Stay up to date with the roadmap progress, announcements and exclusive discounts feel free to sign up with your email.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.