Home Writing Reading

til / Rewrite using go

It’s less than two weeks since I last rewrote this website. That has to mean it’s time for another rewrite, right?

It started with something as odd as me signing up to run the Stockholm Half Marathon. I created a small Node script that calculated the average pace I would need to maintain for different finishing times. Huh, I wonder how much faster this script that takes ~20 ms to run would be in OCaml (it was around twice as fast). What about Go? And here’s the squirrel moment. Oh, damn, Go has built-in support for templates, and running database queries, and it’s super fast and can be deployed to Fly.io!? I have to test it.

I started migrating and moved fast. Picking up the basic concepts and being productive in Go was straightforward. It took me a couple of days of working in my spare time, but now this site is running on Go. The difference in startup times is actually insane. These are numbers from the last few days from the old Bun (Elysia) based server and the Go server.

Both use htmx on the client side, so the templates only needed to be updated to conform with Go’s template engine. The logic is all on the server side.

Startup times #

Bun #

Value Machine Started Machine Reachable
Average 695.43 ms 939.01 ms
Max 974.18 ms 1,456.36 ms
Min 627.16 ms 710.39 ms

Go #

Value Machine Started Machine Reachable
Average 682.47 ms 7.25 ms
Max 760.05 ms 7.96 ms
Min 642.68 ms 5.90 ms

Started time is, as expected, the same, but the time it takes for the machine to be reachable improved by over 99% on average. Bun regularly became reachable in over one second, but Go never went above 8 ms.

Memory #

First, memory usage from the Bun version, between 110 MB and 180 MB. I’m guessing that the lower number is when it’s hibernating, and the higher is when started? The drop-off to a consistent level is when I switched the DNS to the Go server.

Second, the Go server with memory usage flat lined at about 47 MB.

Not only that, but the code feels simple to understand, even with my limited knowledge of Go.


  • Loading next post...
  • Loading previous post...