guile-user
[Top][All Lists]
Advanced

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

Re: neat symbol speedup


From: Han-Wen Nienhuys
Subject: Re: neat symbol speedup
Date: Sat, 6 Oct 2001 00:04:41 +0200

address@hidden writes:
> Isn't this just an application of standard common sense when looking
> to improve performance?  It's pretty obvious that you shouldn't do
> unnecessary and repetitious computation inside a loop, especially when
> it involves processing a string.

> Or am I missing something extra in the GCC stuff?

I'm not sure. I'm working on a rather large GUILE application, and it
references symbols from 95 of the 250 C++ sourcefiles. It is possible
to precompute those symbols by hand, i.e.

blah.c: 

  static SCM foo_symbol;
  init_blah_module ()
  {
    foo_x_symbol = gh_symbol2scm ("foo!");
  }

  SOME_MAGIC_SNARF_MACRO_TO_CALL_INIT(init_blah_module)

  blah_blurble ()
  {
    bar (foo_x_symbol);
  }

But it is a lot of superfluous code, and in a large application like
lilypond, all that code could easily become a source of bugs.
Moreover, foo_x_symbol just doesn't read as nicely as symbol2scm("foo!")

With my macro, you can use symbol2scm whenever you want to have a
symbol, and you don't have to worry whether it is too expensive to put
into a loop. Also, no need for extra initialization code, just put

  #include  "macro.h"

  blah_blurble ()
  {
    bar(symbol2scm ("foo!"));
  }

BTW, there was a bug (at least on redhat 7.1/gcc 2.96) in the code I
posted. Here is a better version:

  #define ly_symbol2scm(x) ({ static SCM cached;  \
 SCM value = cached; \
/* We store this one locally, since G++ -O2 fucks up else */   \
 if (__builtin_constant_p (x))\
   value = cached =  scm_permanent_object (gh_symbol2scm((char*)x));\
 else\
  value = gh_symbol2scm ((char*)x); \
  value; })
#else


-- 

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




reply via email to

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