On Sat, Feb 15, 2003 at 10:30:14AM -0500, rif wrote:
> ;; Runs as fast as test-1, conses 0 bytes
> (defun test-3 ()
> (declare (optimize (speed 3) (safety 0) (debug 0)))
> (dotimes (i 30000)
> (funcall #'nmap-df-vector-2 #'square-df *vector*)))
>
> Have I got the idea?
Yup--it completely slipped my mind that I was basically using a
compiler macro like to get an inline function (despite having
used one only a few forms previously...). I might have been
thinking it was necessary to coerce the compiler into using
the inline expansion of the function passed as an argument...
One thing to keep in mind:
In TEST-3, Python (CMUCL, SBCL, and SCL's compiler, not
the scripting language) was able to inline NMAP-DF-VECTOR-2
because you were FUNCALL'ing the symbol its global definition
is bound to directly. If you use #'NMAP-DF-VECTOR-2 as the
argument to a higher-order function that's not being
inlined, Python won't be able to use the inline expansion and
will just call it like a regular function. For example:
(defun test-4 (function)
(declare (optimize (speed 3) (safety 0) (debug 0)))
(dotimes (i 30000)
(funcall function #'square-df *vector*)))
(test-4 #'nmap-df-vector-2) runs as slowly as TEST-2
Yet another thing you might want to try, if you haven't already,
is to tune the GC to be a bit more heavy-allocation friendly.
For example:
(setf *bytes-consed-between-gcs* (* 64 1024 1024))
Cuts the running time of TEST-2 nearly in half. This isn't nearly
as dramatic as the inlining, but will certainly help a bit in the
cases where you can't inline.
Gabe Garza