Channels ▼

Christopher Diggins

Dr. Dobb's Bloggers

What Type of Optimization Excites Me

July 15, 2008

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:

  1. Functional programming (FP) is considered inefficient
  2. Because FP is considered inefficient  it isn't used much, and is deemed unidiomatic.
  3. Because FP is unidiomatic, benchmarks ignore it 
  4. Because benchmarks ignore FP style code it isn't addressed by compiler writers
  5. 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.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video