[wxruby-users] Drawing thread not getting enough time from scheduler?
Alex Fenton
alex at pressure.to
Wed Jan 2 19:29:27 EST 2008
Jay McGavren wrote:
> It did speed things up a bit, but it still runs many times faster (55
> seconds vs. 5 seconds) if I join the animation thread.
>
...
> Any idea how I can get the thread scheduler to devote a bit more time
> to animation, without completely freezing the GUI?
Just had a chance to try your code. For me on OS X it doesn't work at
all if thread.join is called, but runs pretty smoothly (about 8s total)
otherwise. At some level you'll also be caught by the granularity of
Ruby's thread time slices (10ms IIRC), and garbage collection, which is
taking up to 9ms tracking wxRuby objects alone in your example.
I see a couple of further potential optimisations in your code which
improve smoothness for me:
* Take the calls to surface.pen= and surface.pen.cap= out of the
30.times loop.
* See whether the drawing could be more efficiently done with a single
draw_polygon (which acccepts an Array of Wx::Points)
Another untested possibility to improve perceived smoothness might be to
drive the animation from a Wx::Timer. Have it run at regular intervals,
calling window.refresh to invalidate the window, then copy from the
bitmap inside an evt_paint handler.
Let us know how it goes...
cheers
alex
More information about the wxruby-users
mailing list