[Ecls-list] More on special variables and multithreading

Yue Li xyly781 at gmail.com
Fri Jan 22 17:36:50 UTC 2010


On Fri, Jan 22, 2010 at 9:40 AM, Juan Jose Garcia-Ripoll
<juanjose.garciaripoll at googlemail.com> wrote:
> 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.
>
  The second and third points seems to me will provide better
performance, so can I say the first one is the current main cause of
the slow down?

> 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))
>
>
   That's so cool, can't wait to use that.Thank you very much for the
great work!

Yue




More information about the ecl-devel mailing list