Write Haskell as fast as C: exploiting strictness, laziness and recursion
cgi.cse.unsw.edu.au
cgi.cse.unsw.edu.au
http://donsbot.wordpress.com/2008/05/06/write-haskell-as-fas...
and the follow-on using fusion,
http://donsbot.wordpress.com/2008/06/04/haskell-as-fast-as-c...
Still, an awesome analysis that traverses the code hierarchy from assembly to Haskell.
Write code. Run. Runs out of memory after 3 hours of protein folding. Check the GHC processed code. Discover that you need to rewrite 5 functions. The premise is that your mental model wasn't good enough to predict this without the GHC processing, so rewrite, run through GHC, stare at code, rewrite again. If that whole cycle is necessary, then this does not sound workable. But I'd be thrilled to learn that I'm missing something.
I've written a fair amount of Haskell, and done a lot of this type of optimization, looking at the core (intermediate representation) and fiddling with pragmas, unboxing, strictness, etc. I've put Haskell on the back burner and gone back to C++ because I spent SO MUCH time doing this. Maybe I'm not being fair, and in another 5 years I'd be able to predict what GHC is going to do as well as I can predict what a C++ compiler will do. But for now, I can't justify the expenditure in time it takes to get a large piece of Haskell code (more than a microbenchmark) to perform at the C/C++ level. If you write idiomatic Haskell you're tracking down stack overflows (the Haskell kind, not the C kind) and misfired optimizations, and if you're writing C-in-Haskell you're better off just writing C. In the end, I think Haskell just isn't (yet) the best language for what I was doing (image processing, graphics, 3d modeling, etc.)
(The short reply to your comment is: yes, you the application writer have to be very aware of what GHC is doing if you want C-level performance.)
I'm not so much looking for what it takes to get code running optimally, as much as having idiomatic code run with "reasonable" performance.