[Ecls-list] More on special variables and multithreading

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Sat Jan 23 16:13:59 UTC 2010


On Fri, Jan 22, 2010 at 6:57 PM, Juan Jose Garcia-Ripoll <
juanjose.garciaripoll at googlemail.com> wrote:

> This flexibility has a consequence, which is a small slowdown due to an
> addition memory read and comparison operations but I am sure the inline
> version will get much better.
>

Inlining C code is not easy, but it is somehow working right now. The things
are getting hairy enough that I had to ditch macros in favor of "static
inline" C functions. This means the code may be faster or slower depending
on what your compiler supports. However I am pretty confident that all GCC
variants, MSVC and Sun's compiler do support "inline" in one form or
another.

Now as for the figures. I am using the code below, stored in a single file,
compiled and loaded. Due to the fact that everything is compiled in the same
translation unit, we ony see the overheads of special variables, not of
function calls, etc. BASE is the basic cost of the loops, FOO2 adds special
variable bindings and FOO adds both binding and reading of special
variables.

In the git/CVS version of ECL the results are as follows (Mac OS X 10.5,
Leopard, gcc-4, no __thread attribute)
 FOO
real time : 1.301 secs
run time  : 1.291 secs
gc count  : 1 times
consed    : 128 bytes
FOO2
real time : 1.011 secs
run time  : 1.003 secs
gc count  : 1 times
consed    : 0 bytes
BASE
real time : 0.158 secs
run time  : 0.155 secs
gc count  : 1 times
consed    : 0 bytes

Using the new implementation of special variables
FOO
real time : 0.265 secs
run time  : 0.263 secs
gc count  : 1 times
consed    : 224 bytes
FOO2
real time : 0.235 secs
run time  : 0.232 secs
gc count  : 1 times
consed    : 0 bytes
BASE
real time : 0.155 secs
run time  : 0.153 secs
gc count  : 1 times
consed    : 0 bytes

As expected, the overhead of reading a special variable is very small, about
30/10e6 ms, while variable binding is larger, 80ms, but way smaller than
before.

I still have a couple problems to solve before promoting this code to CVS.

Juanjo

(declaim (optimize (speed 3) (safety 0)))

(defvar *a* 3)

(defun faa (x) x)

(defun foo (x)
 (dotimes (i 10000000)
  (declare (fixnum i))
  (let ((*a* x)) (faa *a*))))


(defun foo2 (x)
 (dotimes (i 10000000)
  (declare (fixnum i))
  (let ((*a* x)) (faa 2))))

(defun base (x)
 (dotimes (i 10000000)
  (declare (fixnum i))
  (faa x)))

(ext:gc t)
(princ 'FOO)
(time (foo 1))
(princ 'FOO2)
(time (foo2 1))
(princ 'BASE)
(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/20100123/0f37e694/attachment.html>


More information about the ecl-devel mailing list