Beware RESTART-CASE in a hot codepath

Tagged as lisp

Written on 2019-11-15 19:00:00

Quick lisp performance tip about using restart-case.

Recently I was hacking on my game-engine, vert. I noticed the framerate lagging. Using SBCL's profiler I found the culprit: calling restart-case inside of a hot code path (in my case, once every game update frame).

To verify I made this bit of code. It times calling restart-case under a loop.

 (loop :for i :from 0 :below 100000 :do
        (continue () :report "Continue")
        (shutdown () :report "Shut down"

The output:

Evaluation took:
  0.006 seconds of real time
  0.006037 seconds of total run time (0.003030 user, 0.003007 system)
  100.00% CPU
  12,192,576 processor cycles
  6,422,512 bytes consed

When using SBCL's time utility, it's a good idea to put your questionable code inside a loop to get a good idea of how it behaves over many calls.

The moral of the story? Don't use restart-case in a hot codepath.

comments powered by Disqus

Unless otherwise credited all blog material Creative Commons License by Ark