logoalt Hacker News

Httpz – Zero-Allocation HTTP/1.1 Parser for OxCaml

80 pointsby noelwelshlast Wednesday at 10:02 AM19 commentsview on HN

Comments

avsmyesterday at 3:38 PM

(author here) I'm just adding data-race free parallelism support to this right now to switch my website over to using it! For those familiar with OCaml syntax, the OxCaml parse function is fun:

    val parse : buffer -> len:int -> #(status * request * header list) @ local
This takes in a buffer and returns an unboxed tuple on the stack, so there's no GC activity involved beyond stack management for each HTTP request.

https://github.com/avsm/httpz/blob/main/lib/httpz.mli#L154

show 2 replies
nospiceyesterday at 5:01 PM

"Zero heap allocations: Parser results are stack-allocated using OxCaml unboxed records and local lists" - honest question, why?

On almost any platform on which you want to run a HTTP server - including bare metal - it usually doesn't matter if you keep state near the stack pointer or not. What matters is that you use it well, making it play well with CPU caches, etc. Or is there something specifically horrible about OxCaml's heap allocator?

show 3 replies
messeyesterday at 7:15 PM

> Local lists (@ local): Header list grows on the stack, not heap

Does this mean unbounded stack growth? I'd much rather heap allocation if that's the case, as at least that can be recovered from in the case of allocation failure (assuming your OS, language, and stdlib allow for it).

show 1 reply
spooneybargeryesterday at 10:42 PM

The OxCaml work is great. I don't use OCaml much but I have been following along with OxCaml as they are doing fascinating work that leverages a lot of research that interests me.

gethlyyesterday at 3:54 PM

ocaml looks more like a spec than actual code.

show 1 reply
infamouscowyesterday at 5:14 PM

I'm excited to see what comes of OxCaml the next few years.