Rewriting it in Rust
31 January, 2025
I seem to have rewritten Zine in Rust. Rewrite it in Rust. It's a cliche, I know, but it has legs.
Rust wasn't part of my plan. Last month I rewrote Zine in Swift but oh boy, I did not get what I expected. Apart from the benefit of things like type safety I had expected Swift to also be faster than the old Ruby version. Nope. That warrants repeating: the Swift version was slower than Ruby.
Ruby on average took around a second to build this site completely. Swift took around 1.5s. There were a few things I could tweak, the Stencil templates I'd started with were the slowest part by far (thanks profiling!), but all of the alternative Swift templates were less well supported, or incomplete, or just as slow, or all of those things. The fastest rewrite I could manage in Swift was on par with Ruby in terms of speed, but with templates that lacked filters. The Stencil templates are ridiculous, but text replacement in Swift generally is just too slow.
Ruby supposedly optimized for developer happiness. The unwritten coda to that of course being "at the expense of the end user." Since at least Ruby 3.0 this developer was never that happy with Ruby either though. The way type hinting works, Ractors, a whole lot of different things big & small seemed off. Swift implicitly makes the same sort of deal. All the affordances are there for the developer. But at the expense of the end user. So I turned to Rust.
Tim Cook's donations & DHH's odes to making America great again of course both helped.
First I moved on to Zola, another static site generator that's written in Rust, & it was gratifyingly faster. Zola took around 0.4s for the whole site. It's not my intention here to critique Zola, it's good, but it does a lot of things I don't need & several things I don't want. It's a big piece of kit with a lot of dependencies (398 last time I looked), & the "pretty" URLs it generates pretty much ruled it out for me. So once again I wrote my own.
There are missing pieces in Rust that continue to annoy me mightily. A lack of named & default arguments are probably at the top of that list. But when I write Rust it feels like I'm moving the world forwards towards some kind of a better future. That's probably me fooling myself, but it's a nice feeling.
For this site I wanted something smaller & more focused than either Zola or the old Zine. In the last seven or eight years since I wrote Zine in Ruby my opinions have changed. Not just around languages, but about what something like Zine should & shouldn't do. I don't use Sass any more, & my thinking now is that deployment should be an action triggered by a git commit, something that can be done via rsync there doesn't need to be included in Zine. Of course I'm not using Github or AWS any more either. So the new Zine is a lot leaner.
Currently with fewer than 10 direct & 50 transitive dependencies Zine takes around 100-150ms to build this site. 0.1s. Ten times faster than Ruby & fifteen times faster than Swift. Strong types, memory guarantees, all that of course. But also fast. Very fast.
I'll keep the code local for the moment. There's a lot of the rewrite I want to rewrite still.