Viltrum: No Wrapper in Between
On July 18, when I wrote the first Viltrum post, its last section ended like this: "No HTTP/2. No TLS. Good; the focus stays."
By October 24 it had both. Its own TLS 1.3 record layer and handshake, HTTP/2 chosen by ALPN, and h2c on the same port. What changed my mind is what this post is about.
What I wanted
My goal was a fast round trip for an API, or for IoT devices talking to each other. A request comes in, the answer goes back without delay. That's it.
V is a good start for that. It is a fast language by design. It compiles to native code, the binary is small, v run doesn't keep you waiting.
The problem was on the framework side. Most of the V web frameworks I looked at were wrappers: a thin layer over another server or library. The router is nice, there's middleware, but the place where bytes come off the socket and turn into an HTTP message is someone else's code. And the speed is only as fast as that code.
Very few frameworks were written in pure V, owned the wire themselves, and focused on exactly this point.
What "owning the wire" means
It's the first sentence of Viltrum's README: "A web framework for V that owns the wire." In practice:
- Its own HTTP/1.1, HTTP/2 and WebSocket engine. Including HTTP/2's HPACK compression.
- Its own TLS 1.3. AES-GCM records on AES-NI and PCLMUL, the handshake with X25519 and RSA certificates. To be honest here: X25519 and the RSA-PSS signing are in C. The rest is V.
- Its own DEFLATE encoder.
- One epoll worker per CPU.
- Zero allocations per request. I don't just claim it. There's a gate in CI: if a request allocates a single byte, the build goes red.
I think the last one matters most. If you want a fast round trip, you want nothing on the request's path that asks for memory. And you can only guarantee that if the whole path is your code. With a wrapper you can't, because whatever the code under the wrapper does, happens.
I wrote TLS for the same reason. In July I was saying "need TLS? put a reverse proxy in front". But a proxy in front means putting another layer I didn't write back on the request's path. There was no point escaping the wrapper only to land in a proxy.
Speed
The second half of the difference is speed, and I measured it.
On October 14, on HttpArena's baseline, Viltrum was 99th out of 151 frameworks. In the run twelve days later, in the Experimental category, it was first out of 19 entries on HTTP/1.1 and first out of 14 on WebSocket. Everything that happened between those two dates is in the repo. I wrote about how I measured it in a separate post, and about why I threw the engine away and rewrote it here.
Vision
Two things make Viltrum different: its vision and its speed. Speed is above. The vision is this: between a request and its answer, nothing I didn't write and can't measure.
1.18.0 came out today. The new example in it, todo_api, came from a PR I didn't write.