Next: , Previous: , Up: Slot Access Optimization   [Contents][Index]


2.23.3.2 inline Declaration

Example:

(defclass foo ()
  (a b))

(defmethod bar ((x foo))
  (declare (ext:slots (inline (foo a))))
  (list (slot-value x 'a) (slot-value x 'b)))

The inline declaration in method bar tells PCL to use compile-time knowledge of slot locations for accessing slot a of class foo, in the scope of the declaration.

Class foo must be known at compile time for this optimization to be possible. PCL prints a warning and uses normal slot access If the class is not defined at compile time.

If a class is proclaimed to use inline slot access before it is defined, the class is defined at compile time. Example:

(declaim (ext:slots (inline (foo slot-a))))
(defclass foo () ...)
(defclass bar (foo) ...)

Class foo will be defined at compile time because it is declared to use inline slot access; methods accessing slot slot-a of foo will use inline slot access if otherwise possible. Class bar will be defined at compile time because its superclass foo is declared to use inline slot access. PCL uses compile-time information from subclasses to warn about situations where using inline slot access is not possible.

Normal slot access will be used if PCL finds, at method compilation time, that

When the declaration is used to optimize calls to slot accessor generic functions in methods, as opposed to slot-value or (setf slot-value), the optimization is additionally not used if

The consequences are undefined if the compile-time environment is not the same as the run-time environment in these respects, or if the definition of class foo or any subclass of foo is changed in an incompatible way, that is, if slot locations change.

The effect of the inline optimization combined with the slot-boundp optimization is that CLOS slot access becomes as fast as structure slot access, which is an order of magnitude faster than normal CLOS slot access.

Variable: pcl::*optimize-inline-slot-access-p*

This variable controls if inline slot access optimizations are performed. It is true by default.


Next: Automatic Method Recompilation, Previous: slot-boundp Declaration, Up: Slot Access Optimization   [Contents][Index]