On Fri, Jan 9, 2009 at 7:19 PM, karol skocik <karol.skocik@...> wrote:
> I would like to optimize our application written with several SBCL
> specific things already baked in, so I am looking for SBCL specific
> options for speeding up mainly CLOS slot access. Juho mentioned on
> #lisp a possibility to add sealing declarations. How do I tell SBCL
> that I want to seal a class that won't be redefined or subclasses
> later in run-time?
The declamation you are looking for is
(declaim (sb-ext:freeze-type foo))
except that it doesn't really help: it doesn't prevent class
redefinitions, and it doesn't help optimize slot-access.
Are you familiar with the performance discussion in
If you need slot accesses with speeds beyond the "slot-value with
constant second argument in defmethod body" described there, you can
use a custom metaclass to provide a :LOCATION argument for slots,
orders the slots based on that in COMPUTE-SLOTS, and use
STANDARD-INSTANCE-ACCESS to access them -- but beating the best-case
slot-value speed is pretty hard, since it has extra support in the
method dispatch machinery.
I had maybe ~80% if slot location sealing written up, which does this
semi-automatically, but the performance win was minimal.
Other tricks to speed up your slot access performance:
1. If you need fast slot-accesses in a DEFUN for some reason (?),
define a multi-value accessor method:
(defmethod values-for-foo ((x bar) (y zot) (z quux))
(values (slot-value x 'a)
(slot-value y 'b)
(slot-value z 'c)))
This allows you to get the fast slot accesses for the slots you need
and pay for the dispatch only one. Most of the time you are better of
using a DEFMETHOD instead of the DEFUN instead, though -- but if
you're not receiving the instances whose slots you are interested in
as arguments, this may be worthwhile.
2. Encapsulate a specialized structure: instead of storing your data
directly in the standard object, define a structure with multiple
typed slots to hold it, and store it in the standard object. Then you
need to pay for the CLOS access only once, and can get the fast
structure object instance access (along with compiler-knowledge of
slot types) after that.
3. Use defstructs. Redefinitions suck, and you don't get multiple
inheritance -- but the slot accesses are fast, compiler knows about
slot types, and you can stack allocate them, so sometimes it is well