Using Allegro's profiler, I found a bottleneck in one tiny function that I had written a long time ago. Despite its simpleton nature, this function is important because it is invoked once for each line of output in the UMLisp print benchmark. By changing the poorly-implemented function
(defun indent-to-level (n &optional (stream *standard-output*)) (format stream (format nil "~~~DT" (+ n n))))
to the more sane
(defun indent-to-level (n &optional (stream *standard-output*))
(declare (fixnum n) (optimize (speed 3) (safety 0) (space 0)))
(dotimes (i (the fixnum (+ n n)))
(declare (fixnum i))
(write-char #\space stream)))
I got a marked speed increase in the print benchmark
| Impl | Old Time (user/total) | New Time (user/total) |
|---|---|---|
| AllegroCL 6.2 | 11.0/11.1 | 8.2/8.3 |
| CMUCL 18e+ | 3.0/3.2 | 2.2/2.3 |
| Lispworks 4.2 | 9.1/10 | 5.8/6 |
| SBCL 0.8alpha.0.22 | 3.9/4.2 | 2.8/3.0 |
| SBCL-MT 0.8alpha.0.14 | 3.7/4.5 | 2.7/3.2 |
| SCL 1.1.1 | 9.2/9.7 | 5.1/5.5 |

Comments (1)
And the further rewrite looks like:
(defun indent-to-level (lvl stream)
(print-n-chars #\space (+ lvl lvl) stream))
(defun print-n-chars (char n stream)
(declare (fixnum n) (optimize speed))
(dotimes (i n)
(declare (fixnum i))
(write-char char stream)))
Posted by Kevin Rosenberg | May 9, 2003 4:05 AM
Posted on May 9, 2003 04:05