Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 723830890bac44da3d113209b14e090b > files > 598

sbcl-1.0.31-1mdv2010.0.i586.rpm

<html lang="en">
<head>
<title>Slot access - SBCL 1.0.31 User Manual</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="SBCL 1.0.31 User Manual">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Efficiency.html#Efficiency" title="Efficiency">
<link rel="next" href="Dynamic_002dextent-allocation.html#Dynamic_002dextent-allocation" title="Dynamic-extent allocation">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--

     This manual is part of the SBCL software system. See the `README'
     file for more information.

     This manual is largely derived from the manual for the CMUCL
     system, which was produced at Carnegie Mellon University and later
     released into the public domain. This manual is in the public
     domain and is provided with absolutely no warranty. See the
     `COPYING' and `CREDITS' files for more information.
   -->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Slot-access"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Dynamic_002dextent-allocation.html#Dynamic_002dextent-allocation">Dynamic-extent allocation</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Efficiency.html#Efficiency">Efficiency</a>
<hr>
</div>

<!-- node-name,  next,  previous,  up -->
<h3 class="section">6.1 Slot access</h3>

<p><a name="index-Slot-access-136"></a>

<h4 class="subsection">6.1.1 Structure object slot access</h4>

<p>Structure slot accessors are efficient only if the compiler is able to
open code them: compiling a call to a structure slot accessor before
the structure is defined, declaring one <code>notinline</code>, or passing
it as a functional argument to another function causes severe
perfomance degradation.

<h4 class="subsection">6.1.2 Standard object slot access</h4>

<p>The most efficient way to access a slot of a <code>standard-object</code> is
by using <code>slot-value</code> with a constant slot name argument inside a
<code>defmethod</code> body, where the variable holding the instance is a
specializer parameter of the method and is never assigned to. The cost
is roughly 1.6 times that of an open coded structure slot accessor.

   <p>Second most efficient way is to use a CLOS slot accessor, or
<code>slot-value</code> with a constant slot name argument, but in
circumstances other than specified above. This may be up to 3 times as
slow as the method described above.

   <p>Example:

<pre class="lisp">     (defclass foo () ((bar)))
     
     ;; Fast: specializer and never assigned to
     (defmethod quux ((foo foo) new)
       (let ((old (slot-value foo 'bar)))
         (setf (slot-value foo 'bar) new)
         old))
     
     ;; Slow: not a specializer
     (defmethod quux ((foo foo) new)
       (let* ((temp foo)
              (old (slot-value temp 'bar)))
         (setf (slot-value temp 'bar) new)
         old))
     
     ;; Slow: assignment to FOO
     (defmethod quux ((foo foo) new)
       (let ((old (slot-value foo 'bar)))
         (setf (slot-value foo 'bar) new)
         (setf foo new)
         old))
</pre>
   <p>Note that when profiling code such as this, the first few calls to the
generic function are not representative, as the dispatch mechanism is
lazily set up during those calls.

   </body></html>