[Kstars-devel] [patch] improve rendering time for stars by a factor of 20

Jason Harris jharris at 30doradus.org
Sun Dec 23 07:24:04 CET 2007


Hello,

I've attached a patch that draws stars twenty times faster than our current 
code.  The difference is made by reinstating something we had in 3.x: a cache 
of star pixmaps covering all sizes and colors, drawn on the map with 
drawPixmap(), instead of using drawEllipse().

The stellar pixmaps are stored in a static QHash in StarObject, and 
initialized once in StarComponent::init().  When a star needs to be drawn, 
the QHash key is constructed from the star's spectral type, and the int() of 
the size parameter passed by StarComponent (e.g., "K07" for a bright red 
star, or "B02" for a faint blue star).

I added timing code to StarComponent to test the time taken by the star 
catalog draw loop.  Try this test: add the timing code without changing 
anything else, then start KStars, and set both of the stars' magnitude limits 
to 10.0.  Zoom out so you can see most of the sky, then press "." to stop the 
clock and advance one time step.  Hit that a few times to get an average 
rendering time for all those stars.  On my machine it was about 7.7 seconds.

Then close Kstars, apply the rest of the patch, recompile, and run the same 
timing test.  On my machine the same rendering loops were taking 0.3 seconds!

I didn't simply apply the code, because I'm a little reluctant to introduce 
such a big change while we're frozen and a couple weeks away from a major 
release.  It appears to work beautifully, but I have not implemented 
color-switching for Star Chart and Night Vision color schemes (not hard to 
do), and there may be some issues that I'm unaware of.

So, I want people's opinion.  Should we consider this a bugfix, or at least a 
regression fix, and add it now?  Or should we hold off until trunk thaws?  
I'd really like some help testing this change if we're going to add it now.

Whatever we decide, exciting times are ahead.  With this fix, we'll be able to 
finally increase the number of stars handled by KStars well into the millions 
with no degradation in performance compared to what it does now.  And 
actually, if we're smart about ignoring faint stars at low zoom, the 
performance should be really good.

regards,
Jason
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stars_as_images.patch
Type: text/x-diff
Size: 6344 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kstars-devel/attachments/20071222/b1b12f7b/attachment-0001.bin 


More information about the Kstars-devel mailing list