Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I improve SWT drawing performance?

I was given the task of improving the performance of a stock market charting software that uses SWT's GC to draw the charts. The chart drawing needs to be improved because the charts sometimes are redrawn many times per second, and it consumes lots of processor time.

After googling a little, I found a blog entry that suggests the direct modification of ImageData objects instead of using GC's methods, promising great performance gains.

It's an easy task to draw horizontal and vertical straight lines and square shapes using this technique, but when it comes to drawing circles and other irregular shapes there is no easy way.

Does anyone know if there is a library to draw shapes on ImageData objects, just like GC's methods do on Image objects?

Also, does anyone know another way to improve SWT performance?

Thanks in advance.

like image 281
Mario Marinato Avatar asked Apr 21 '26 11:04

Mario Marinato


1 Answers

Measure the performance of your solution. Where is most time spent? Guessing is not enough. In 90% of the cases, your guesses will be wrong. If you don't know, you can't solve the issue.

SWT itself is not slow. In fact, SWT is just a very thin layer over the respective OS system calls to draw.

One of the problems of SWT is that it's synchronized. To make sure that threading issues cause no problems, there is a global lock. So if you render from several threads at once, this can be a problem.

Or maybe you're not caching resources like colors and fonts properly. These are expensive to create. How many GCs do you create? Do you keep one around or do you create a new one per frame?

But I'm just guessing here. Unless you can prove with a performance monitor "most time is spent in ...", there is no way to help you.

like image 145
Aaron Digulla Avatar answered Apr 23 '26 00:04

Aaron Digulla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!