Sorry for the silence

Banshees on the WindSorry for the silence of the past few days; I’ve been working on a possible fix to the theme rendering code, after the test suite told me that the part which calculates the value of expressions was a bit slow.  Currently it tokenises during theme load but parses every evaluation.  I thought that if I parsed it into some stack-based form on theme load, it might take slightly longer to load a theme, but everything would draw faster by just evaluating the stack-based version.  (I also took the opportunity to do all floating-point arithmetic using scaled integers, because I’m stuck in 1988.)

In practice, though, the results have been disappointing: it only seems to have saved a few microseconds here and there.  So it’s probably not worth the disruption of merging it, though it does also make the code 584 lines shorter, mainly through its use of a GScanner instead of tokenising in house.  I think it also makes the code a bit easier to read.  I’ve put the patch up in case anyone fancies suggesting how it can be sped up a bit further.

(One optimisation that the existing version does that the patch doesn’t do is evaluate constant expressions at theme load time– so if you have Fred+1 where Fred is a constant equal to 2, it will store just 3 and not bother doing the evaluation.  I’m not sure whether that would give much extra speed to the new code.)

Still, experiments are worth doing even if they fail!

Photo © Dead Air, cc-by-nc-sa.

4 Comments

  1. Olivier Samyn
    Posted February 2, 2009 at 3:22 pm | Permalink

    I just had a look at your patch…
    Maybe avoiding the switch statement in the evaluation loop will optimize your code.

    Using an array of function pointers or some gcc extension like [1] should do it…

    If I only had time to test this…

    [1] http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Labels-as-Values.html

  2. Posted February 3, 2009 at 4:03 am | Permalink

    That does seem to make a difference. Thank you.

  3. Posted February 3, 2009 at 2:13 pm | Permalink

    Hello, Admin.
    Can I take a photo from your blog?
    Of course, i will place a backlink to source.
    Thanks.
    Yours Hobosic

  4. Posted February 3, 2009 at 3:21 pm | Permalink

    @Hobosic:

    All the photos posted on this blog are licenced under Creative Commons and none of them are original to us. The attribution at the foot of each post says where they come from. Most of them are taken from Flickr. If you click the photo it will take you to the original page.