Sorry 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.