2009/6/28 <whalliburton@...>:
>
> I notice that there are particular slot access performace gains while
> inside a defmethod. Is it advantageous to convert defuns into sole
> defmethods just to gain this advantage?
Generally speaking yes:
(defun foo1 (thing)
...
(slot-value thing 'foo)
...
(slot-value thing 'bar))
will do two generic function calls for slot-access, whereas
(defmethod foo2 ((thing thing))
...
(slot-value thing 'foo)
...
(slot-value thing 'bar))
will use _no_ gf calls for slot-access (assuming permutation vector
optimization could be performed: no slot-value-using-class, etc), so
total number of GF calls is one less than otherwise.
However, if both used _slot_accessors_ instead of SLOT-VALUE, then in
the current scheme of things in SBCL the ordinary function would win.
(Permutation vector optimization could be extended to accessors, but
this has not been done yet -- it's a bit trickier.)
Cheers,
-- Nikodemus
|