[Ecls-list] More on special variables and multithreading

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Fri Jan 22 15:40:57 UTC 2010


I have sketched an implementation of special variables that works _mostly_
like SBCL's. The idea is that each symbol which is dynamically bound is
assigned an index. This index is used to look up in a thread-local storage
that contains the actual values of the symbol.

The difference between SBCL's implementation and what I have done are
- Right now the sketch is not inlined -- requires a function call per lookup
- The storage region may grow and need not have the same size for each
thread
- Indices into the table are reused when symbols are garbage collected.

Results are encouraging. For a simple test program shown below the old
implementation gives

FOO
real time : 0.817 secs
run time  : 0.817 secs
gc count  : 1 times
consed    : 0 bytes
BASE
real time : 0.203 secs
run time  : 0.203 secs
gc count  : 1 times
consed    : 0 bytes

Once we subtract the cost of calling BASE with the improvements of hash
tables this gives 617 ms for 1e7 lookups and bindings.

The new scheme OTOH

FOO
real time : 0.301 secs
run time  : 0.300 secs
gc count  : 1 times
consed    : 0 bytes
BASE
real time : 0.203 secs
run time  : 0.203 secs
gc count  : 1 times
consed    : 0 bytes

that is 100 ms, or 1/6th.

(require 'cmp)
(proclaim '(optimize (speed 3) (safety 0)))
(defvar *a* 3)
(compile 'faa '(lambda (x) x))
(compile 'foo '(lambda (x)
         (dotimes (i 10000000)
           (declare (fixnum i))
           (let ((*a* x)) (faa *a*)))))
(compile 'base '(lambda (x)
         (dotimes (i 10000000)
           (declare (fixnum i))
           (faa x))))
(ext:gc t)
(princ 'FOO)
(time (foo 1))
(time (foo 1))
(princ 'BASE)
(time (base 2))
(time (base 2))


-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20100122/b2b25023/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: new-special-vars.diff
Type: application/octet-stream
Size: 12458 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20100122/b2b25023/attachment.obj>


More information about the ecl-devel mailing list