What Type of Optimization Excites Me
I tend to get excited by estoeric stuff ignored by the mainstream. When it comes to optimization, I am really excited about the potential for optimizing code written in the functional programming style. Especially FP code that is succinct and clear.
I read this the other day:
The Erlang code is written in a Haskell-style, with lots of folds and zips, which is usually not the choice for Erlang if you need high-performance.
In case you don't know Erlang is a functional programming language that is excellent at robust and efficient parallelization. Haskell is a pure functional programming language that can be used to write code that you can prove to be safe (for some meanings of "safe").
What is interesting to me is that the functional programming, and in particular the Haskell community, has spent a lot of time and energy making folds and zips efficient. In fact, there are optimizations that can be performed by a Haskell compiler that are kind of mind-blowing. The reason though that folds and zips interesting is that enable incredible succinct and elegant code. Consider the Cat code for reversing a list:
nil [cons] fold
Pretty neat, huh? This isn't just a feature of Cat, the Haskell standard library (called the Haskell prelude) is filled with cool code like that. So why don't we see this kind of succint and elegant code in other languages? Because most compilers can't optimize "fold" and higher-order functions properlyin different languages, the bread and butter of the functional programming style.
In general functional programming optimizations in mainstream languages suffer the following fate:
- Functional programming (FP) is considered inefficient
- Because FP is considered inefficient it isn't used much, and is deemed unidiomatic.
- Because FP is unidiomatic, benchmarks ignore it
- Because benchmarks ignore FP style code it isn't addressed by compiler writers
- Because compiler writers ignore optimizing FP code it is inefficient.
I can't help get hot under the collar when I think how every damn mainstream langauge compiler implements higher-order functions as clumsy old objects. This is just awful.
Anyway, I try not to get too annoyed by the situation and just look at it as an opportunity to doing something new and cool. Perhaps someday I will finish my VM, and show some people how its done.
Drop me a line at cdiggins@gmail.com if you want to know more about all this stuff.

