Article View: comp.lang.clos
Article #122Re: Accessors specified in a defclass don't seem to use slot-value in
From: Trent Lange
Date: Fri, 14 Aug 1992 21:28
Date: Fri, 14 Aug 1992 21:28
60 lines
3521 bytes
3521 bytes
In article <28265.9208141401@subnode.aiai.ed.ac.uk> jeff@aiai.edinburgh.ac.uk (Jeff Dalton) writes:
>
>Ordinary accessors can be efficient by not going through
>slot-value-using-class, but what about the accessors that
>_do_ have to go through slot-value-using-class? How big
>a price do you pay for actually using the MOP?
>
>-- jd
In the new versions of PCL, that depends entirely upon your
slot-value-using-class methods. When creating the method-function
for accessors, PCL calls compute-applicable-methods on
slot-value-using-class or (setf slot-value-using-class) to tell
whether it is an ordinary accessor method. If it is, then it uses
the optimized accessor method-function, which precomputes the slot-location
and its type (instance or class-allocated), and essentially looks like
this for standard instances/slots:
(let ((index <index-num>))
#'(lambda (instance) (svref (std-instance-slots instance) index)))
In reality it also has a check for whether the slot value returned is
unbound, but as you can see, it's about optimal.
If the accessor is non-ordinary, PCL uses the actual slot-value-using-class
dispatch function on the given instance for its method-function. It
precomputes the instance's class and the slot's effective-slot-definition.
The accessor's method-function then looks like this:
(let ((class <instance-class>)
(slotd <instance-classes-slot-definition>)
(svuc-dispatch-function <...>))
#'(lambda (instance)
(funcall svuc-dispatch-function class instance slotd)))
Because of this, non-ordinary accessors are actually faster than
directly calling slot-value-using-class, since the slot-definition
is stored and because accessor generic-functions only have to do
dispatch on one parameter (the instance), rather than the three
required parameters that s-v-u-c does.
Compared to optimized accessors, this can be relatively fast or slow,
depending on your s-v-u-c methods. However, it will probably be slower
than the optimized accessor method-functions, since it would be difficult
to cache the slot locations in user-defined s-v-u-c methods like the
optimized accessors do. (The standard s-v-u-c method is definitely
slower than optimized accessors, since it looks up the slot's location
with the slot-definition-location generic function.)
An optimization hint is that non-ordinary accessors will take only as
long as the defined s-v-u-c method function if the effective s-v-u-c
method completely overrides the standard method (e.g. as a primary
or :around method that does not call call-next-method). There is some
extra overhead for the dispatch function to handle combined methods
otherwise. So if you're really looking for the best possible
performance, you might want to make sure your defined s-v-u-c method
overrides the primary and includes a copy of the standard s-v-u-c code
(from PCL's slots.lisp file) as necessary.
- Trent Lange
Technical Details
Message-ID:
<1992Aug14.212838.10193@cs.ucla.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!wupost!usc!elroy.jpl.nasa.gov!ucla-cs!lanai.cs.ucla.edu!langeReferences:
<28265.9208141401@subnode.aiai.ed.ac.uk>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.clos Path: arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!wupost!usc!elroy.jpl.nasa.gov!ucla-cs!lanai.cs.ucla.edu!lange From: lange@lanai.cs.ucla.edu (Trent Lange) Subject: Re: Accessors specified in a defclass don't seem to use slot-value in Message-ID: <1992Aug14.212838.10193@cs.ucla.edu> Sender: usenet@cs.ucla.edu (Mr Usenet) Nntp-Posting-Host: lanai.cs.ucla.edu Organization: UCLA Artificial Intelligence Laboratory References: <28265.9208141401@subnode.aiai.ed.ac.uk> Date: Fri, 14 Aug 92 21:28:38 GMT Lines: 61