Optimizing Lisp

Over at the Lisp Subreddit, they have a pointer to an interesting 2006 paper on How to make Lisp go faster than C by Didier Verna. One of the persistent myths about Lisp is that it’s slow. That comes from the old days when Lisp was interpreted but it hasn’t been true for a long time.

Verna shows that Lisp can be as fast as C and sometimes even a bit faster. This always seems counterintuitive but it shouldn’t. After all, the C compiler and the Lisp compiler both do the same thing: they compile their source languages into machine language. It’s really (mostly) a matter of how good the compilers are. Yes, there are things like garbage collection but especially for numerical work there’s no reason that one should run faster than the other.

What’s interesting to me are the reddit comments. They were mostly along the lines of, “Yeah but you have to add all these yucky declarations into the source code and it makes it ugly.” To me that completely misses the point. Leaving aside the fact that you always need declarations in C, the point is you can quickly develop a first version, working interactively with Lisp. If the situation calls for it, you can speed things up by adding declarations and declamations to the code. Usually you won’t need to but when you do, Lisp has the appropriate tools available. You get the best of both worlds: you can easily prototype an application and then, if needed, make it production-strength by added a few declarations.

In any event, if you use Lisp and would like a nice introduction to optimizing your code, give Verna’s paper a read.

This entry was posted in Programming and tagged , . Bookmark the permalink.