emacs.d/clones/www.sbcl.org/sbcl-internals/The-Cacheing-Mechanism.html
2023-01-18 20:30:47 +01:00

94 lines
4.1 KiB
HTML

<html lang="en">
<head>
<title>The Cacheing Mechanism - SBCL Internals</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="SBCL Internals">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Discriminating-Functions.html#Discriminating-Functions" title="Discriminating Functions">
<link rel="prev" href="Cacheing-and-Dispatch-Functions.html#Cacheing-and-Dispatch-Functions" title="Cacheing and Dispatch Functions">
<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 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">
<p>
<a name="The-Cacheing-Mechanism"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="Cacheing-and-Dispatch-Functions.html#Cacheing-and-Dispatch-Functions">Cacheing and Dispatch Functions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Discriminating-Functions.html#Discriminating-Functions">Discriminating Functions</a>
<hr>
</div>
<!-- node-name, next, previous, up -->
<h3 class="section">3.5 The Cacheing Mechanism</h3>
<p>In general, the cacheing mechanism works as follows: each class has an
associated wrapper, with some number of uniformly-distributed random
hash values associated with it; each cache has an associated index into
this pseudovector of random hash values. To look a value up from a
cache from a single class, the hash corresponding to the cache's index
is looked up and reduced to the size of the cache (by bitmasking, for
cache sizes of a power of two); then the entry at that index is looked
up and compared for indentity with the wrapper in question. If it
matches, this is a hit; otherwise the cache is walked sequentially from
this index, skipping the 0th entry. If the original index is reached,
the cache does not contain the value sought<a rel="footnote" href="The-Cacheing-Mechanism.html#fn-1" name="fnd-1"><sup>1</sup></a>.
<p>To add an entry to a cache, much the same computation is executed.
However, if there is a collision in hash values, before the cache is
grown, an attempt is made to fill the cache using a different index into
the wrappers' hash values.
<p>Wrappers are invalidated for caches by setting all of their hash values
to zero. (Additionally, they are invalidated by setting their
<code>depthoid</code> to -1, to communicate to structure type testers, and
their <code>invalid</code> to non-<code>nil</code>, communicating to
<code>obsolete-instance-trap</code>.
<p>The hash value for multiple dispatch is computed by summing all of the
individual hash values from each wrapper (excluding arguments for which
all methods have <code>t</code> specializers, for which no dispatch
computation needs to be done), jumping to the cache miss case if any
wrapper has a zero hash index.
<p>(FIXME: As of sbcl-0.9.x.y, the generality of multiple hash values per
wrapper was removed, as it appeared to do nothing in particular for
performance in real-world situations.)
<p>References (O for working BibTeX):
<p>The CLOS standards proposal
<p>Kiczales and Rodruigez
<p>AMOP
<div class="footnote">
<hr>
<h4>Footnotes</h4><p class="footnote"><small>[<a name="fn-1" href="The-Cacheing-Mechanism.html#fnd-1">1</a>]</small> Actually, there's
some kind of scope for overflow.</p>
<hr></div>
</body></html>