guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

neat symbol speedup


From: Han-Wen Nienhuys
Subject: neat symbol speedup
Date: Sat, 29 Sep 2001 00:45:48 +0200

Hi there,

I present to you to the following trick. If you use a lot of constant
symbols in your C code, e.g.

        void foo (Bar * b)
        {
                ...

                for (very-often)
                  b->lookup_key (gh_symbol2scm("some-constant-symbol"))

                ...
        }

then you can use the following trick with GCC to eliminate
runtime gh_symbol2scm() calls:

        #define symbol2scm(x) ({ static SCM cached;  \
         (__builtin_constant_p (x)) \
           ? ((cached) ? cached : cached = gh_symbol2scm((char*)x)) \
             : gh_symbol2scm(x); })

The cost of this is one static variable for every symbol2scm() use,
and one boolean evaluation for every call, which is considerably
cheaper than gh_symbol2scm (). Maybe this is a nice addition to the
tricks section of the GUILE manual, if it exists?

It sped up LilyPond, a large and rather complex program, by 5 %. Given
the amount of trouble it took, this definitely is worth the
effort. (Last weekend I spent my entire sunday hacking to get a mere
10%.)






-- 

Han-Wen Nienhuys   |   address@hidden    | http://www.cs.uu.nl/~hanwen/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]