arya's optimisations


updated 2024-10-09

Optimising code is an art. Designing a perfectly optimised algorithm is a slow, methodical process which really forces you to understand the problem you're trying to solve. You have to know your input -- not just the theoretical format it is in, but what realistic instances of it will look like. By prioritising common cases, you can decrease your average runtime. Likewise, choosing the right output format is difficult—you have to balance the efficiency of generating the output with the ease of extracting information from it. This is a really enjoyable process to me.

The drawback of optimisation is that it might not be worth it. I enjoy optimizing code because high performance is fun, but also because I want software to be more resource-efficient. An optimized program uses more CPU resources and so is more power-hungry, but the decrease in runtime results in a net reduction in energy consumption. But this doesn't matter if users will spend the additional time they have on running more instances of the program. For use cases like cryptocurrency and machine learning, where the amount of computation we perform is growing unboundedly, optimization may actually increase energy consumption.

I spent a while thinking about projects I'd like to work on which don't suffer from this problem. I think the most valuable project for me to spend time on is a highly-optimized C compiler. There are hundreds of millions of lines of C code that get compiled regularly, and I believe these compilations can be much faster and much more resource efficient. The simplicity and stability of C also makes it a good candidate for thorough optimization, compared to e.g. Rust.