Always pause for reflection
I caught myself doing something rather foolish last night and I thought it would serve as a nice reminder for people who fall into the same trap I did.
In short, I found myself rewriting library functions. Stupid, I know, but sometimes you get caught up in a context that doesn't have you stopping to assess what it is you're doing. I was profiling some different implementations of things and at one point I wrote
(loop for elem in list thereis (funcall test check (funcall key elem)))
instead of
(find check list :test test :key key)
and I was wondering why the function it was in was a bit of a laggard. (To be precise, the latter was between 6 and 7 times faster than the former!) I had my head so buried in the problem that I couldn't see the forest for the trees.
This is just further reinforcement for the notion that you should stand up every now and then and take stock of what it is you are doing.

3 comments:
Heh, loop!!
I never find me using it (I don't hate loop, but rather than using it I always find it more concise to write some appropriate macro instead).
I guess if the interpreter had picked up your error, and fixed it for you, then it would be real reflection.
Really, there wouldn't be much of a performance difference here if the optimiser was good - the cost model is not intuitive. There are many occasions when the loop idiom is slightly different, making FIND inappropriate, but to pay a 600% performance penalty for doing this seems bad...
Post a Comment