zlacker

My fast zero-allocation webserver using OxCaml

submitted by noelwe+(OP) on 2026-02-02 10:45:44 | 156 points 50 comments
[view article] [source] [go to bottom]

NOTE: showing posts with links only show all posts
◧◩
16. avsm+zO[view] [source] [discussion] 2026-02-02 16:12:02
>>boltzm+wy
We do now though, with OxCaml! The local stack allocation mode puts in quite a strong constraint on the shape of the allocations that are possible.

On my TODO list next is to hook up the various O(x)Caml memory profiling tools: we have statmemprof which does statistical sampling, and then the runtime events buffer, and (hopefully) stack activity in OxCaml's case from the compiler.

This provides a pretty good automation loop for a performance optimising coding agent: it can choose between heap vs local, or copy vs reference, or fixed layout (for SIMD) vs fragmentation (for multicore NUMA) depending on the tasks at hand.

Some references:

- Statmemprof in OCaml : https://tarides.com/blog/2025-03-06-feature-parity-series-st...

- "The saga of multicore OCaml" by Ron Minsky about how Jane Street viewed performance optimisation from the launch of OCaml 5.0 to where they are today with OxCaml https://www.youtube.com/watch?v=XGGSPpk1IB0

◧◩
22. aseipp+0Y[view] [source] [discussion] 2026-02-02 16:59:19
>>boltzm+wy
There are ongoing projects like Granule[1] that are exploring more precise resource usage to be captured in types, in this case by way of graded modalities. There is of course still a tension in exposing too much of the implementation details via intensional types. But it's definitely an ongoing avenue of research.

[1] http://granule-project.github.io/granule.html

◧◩◪◨
23. nh2+v11[view] [source] [discussion] 2026-02-02 17:17:31
>>pkal+JT
Who uses the second meaning?

In my experience, "purely functional" always means "you can express pure functions on the type level" (thus guaranteeing that it is referentially transparent and has no side effects) -- see https://en.wikipedia.org/wiki/Pure_function

◧◩◪◨⬒
33. whatis+zf1[view] [source] [discussion] 2026-02-02 18:24:42
>>AlotOf+Q91
But do bitwise copies when moving not also possibly incur that, even without Copy? If the optimizer doesn't optimize it away? Since movement can happen by copying bits and releasing the old bits, as long as there is no UnsafeCell in the type, or something along those lines?

https://www.reddit.com/r/rust/comments/vo31dw/comment/ieao7v...

◧◩
35. avsm+Ph1[view] [source] [discussion] 2026-02-02 18:34:21
>>int3tr+fe1
Good point; I've decided to simply not support HTTP/1.1 pipelines, and to have a connection pooling layer for HTTP/2 instead that takes care of this.

In OxCaml, it has support for the effect system that we added in OCaml 5.0 onwards, which allows for a fiber to suspend itself and be restarted via a one-shot continuation. So it's possible to have a pipelined connection stash away a continuation for a response calculation and be woken up later on when it's ready.

All continuations have to be either discarded explicitly or resumed exactly once; this can lead to memory leaks in OCaml 5, but OxCaml has an emerging lifetime system that guarantees this is safe: https://oxcaml.org/documentation/parallelism/01-intro/ or https://gavinleroy.com/oxcaml-tutorial-icfp25/ for a taste of that. Beware though; it's cutting edge stuff and the interfaces are still emerging, but it's great fun if you don't mind some pretty hardcore ML typing ;-) When it all settles down it should be very ergonomic to use, but right now you do get some interesting type errors.

◧◩◪◨
38. johnbe+Bk1[view] [source] [discussion] 2026-02-02 18:49:29
>>Neutra+O51
https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/line...

Experimental and of course one can debate whether Haskell is mainstream but I figured it merits a mention.

◧◩◪
41. boltzm+1o1[view] [source] [discussion] 2026-02-02 19:06:26
>>zozbot+hT
do they allow the following? >>46859860
◧◩
49. pjmlp+x44[view] [source] [discussion] 2026-02-03 12:29:12
>>hutao+2E2
OCaml already has that spot for quite some time, the problem is more cultural than technical.

Back in my day we would consider writing compiler toolchains systems programming as well.

"Unix system programming in OCaml", originally published in 1991, latest update 2014.

https://ocaml.github.io/ocamlunix/

◧◩
50. crypto+X06[view] [source] [discussion] 2026-02-03 21:37:53
>>boltzm+wy
https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/line...
[go to top]