Advent of Code, OCaml, and lethargy
No AI, generative or otherwise, was involved in writing any part of this post. All flaws are mine and mine alone, and I prefer it that way: authentic flaws over artificial perfection.
I've been doing Advent of Code every year that it has been running. It makes December one of my favorite times of the year: for 25 days a year, I wake up and know that there's an exciting programming problem waiting for me. I haven't fully completed most years, but I still thoroughly enjoy participating, and I tend to come back to problems I haven't solved throughout the rest of the year.
Advent of Code has a competitive element in the form of a leaderboard of solving times: the earlier you submit a correct solution, the more points you get. This form of competition has never really interested me. If nothing else, waking up that early, barely remembering my own name, and immediately throwing myself at solving programming puzzles is just not enjoyable for me.
Instead, I am much more drawn to performance optimization. Rather than writing code fast, I enjoy writing fast code1 :)
What makes solving Advent of Code puzzles so enjoyable fun to me is that you can almost always write a simple, straightforward solution that runs quickly enough to give you an answer2, and then you can iterate on your solution to make it run faster. Doing so over the past few years has taught me a bit about performance optimization. For example:
- tooling to run microbenchmarks (e.g. Go's builtin benchmarks and Google's
benchmark
library for C++) and gather statistically significant samples of runtime and memory usage; - choosing appropriate data structures and algorithms (and reading up on new ones);
- running profilers to figure out where your solution is spending most of its time, and optimizing that;
- studying the input data for patterns that can be exploited without overfitting to a specific input;
- and more.
Not only have I enjoyed solving the problems and learning some performance optimization skills, it has also been a pleasant way to learn new programming languages. Which brings me to OCaml.
One of the sponsors of Advent of Code 2024 was the quantitative trading firm Jane Street. One thing that they are known for is that they primarily write code in the functional programming language OCaml (and have contributed much to open source OCaml). I don't know much about the quantitative trading world, but I know that they really care about performance in their code. Firms like Jane Street optimize on the level of nanoseconds as that gives them a competitive edge in the business.
This piqued my curiosity: what is it about OCaml that makes it so good for writing performance-critical code that Jane Street chooses to rely on it3? Can I also learn a bit of OCaml to solve some Advent of Code puzzles, and apply tools and techniques I've learned to improve the performance of my solutions so they also run fast? I've been itching to learn something new related to programming, so let's try!
I will (try to) take some notes about this process and write about them here, on this blog. Maybe the things I stumble upon along the way can be of use (or entertainment) for someone else, including my future self. At the very least, I know that writing stuff down helps me really understand and remember it.
So we've covered Advent of Code and OCaml, but what about that third word in the title, "lethargy"? Fun puzzles and programming languages aside, there is another reason, a real reason, behind writing all this. It's much more personal. The following paragraphs are an attempt at being vulnerable and putting into words something I suffer from, because I believe it can be healthy (to a certain extent).
Sorry for the word count. I wrote something long because I didn't have time writing ability to write a short one.
For an extended period of time -- months, maybe even years -- I have been plagued by ennui and lethargy. The hobbies I used to enjoy -- making music, cooking, gaming, tennis, etc -- have felt overwhelming and impossible to get back into without huge time and energy commitments. I used to be very curious about the world and had an at times insatiable hunger for learning about the world, especially about software, computer science, and mathematics, but that hunger has been gone for a long while.
In general life hasn't felt fun or enjoyable. It has just felt like a series of actions I take to survive from one week to the next. Eat, go to work, come home, sink into the couch and feel sorry for myself, repeat. I can't accurately put into words how difficult it has felt at times to not do and not want to do anything. It's a state of mind I do not wish upon anyone (though I also know I am far from alone in it) because it's so very draining, without actually requiring much energy.
Recently the thought came to me that maybe a big part of my declining mental health is an imbalance of consumption vs. creation, skewed heavily towards the former. I consume so much stuff -- YouTube, Hacker News, Lobsters, various social media feeds -- but I don't create anything of my own. One way of putting it is that I have felt like an outsider to the world: I observe the world by seeing what everyone else is doing, but I'm not participating myself, so is there really a place for me here on Earth?
I am acutely aware that strong perfectionist tendencies heavily pushes the balance towards consumption instead of creation. It's much easier to take in what everyone else has done than facing your own anxieties of putting something out there that is less than perfect. Even this post -- I've been trying to write this post for so long, turning the words and sentences over and over in my head, rethinking the structure, figuring out what I'm really trying to say, writing and editing and writing and editing ad nauseum4.
Along with the aforementioned ennui and lethargy has come a vague, abstract urge that I need to express something, somehow. Putting my own writing out on the public Internet feels terrifying, because there's this sense of dread that something terrible will happen to me and my relationships to others. A sense that maybe I'd write something that my employer doesn't like and it'd cost me my job (and/or future opportunities); or that I appear incompetent as I learn things I "should definitely know at this point"; or that people close to me think that I'm unhinged and distance themselves from me.
I hope that by writing this post -- and hopefully the future ones focused on the actual Advent of OCaml project I'm envisioning -- I can start shifting the balance of consumption vs. creation back to something healthier. I hope that learning something new, and sharing it with an (anonymous, imaginary) audience can ignite the spark of wonder and curiosity I used to feel about the world. I hope that by starting with the behavior of creating and publishing, that the joy and motivation will come later.
In the end, I just want to feel like a participant in this world and stop doubting whether I have a place here.
Or at least I attempt to write fast code; I don't claim to be great at it.↩
It is an explicit design goal of Advent of Code that "every problem has a solution that completes in at most 15 seconds on ten-year-old hardware".↩
Since writing this I've learned that Jane Street are actually maintaining and using a set of performance-oriented extensions to OCaml, dubbed OxCaml.↩
I'm still not happy with it, but eventually I just had enough and decided to publish it.↩