Joel VanderWerf
12/12/2006 5:05:00 PM
Joel VanderWerf wrote:
>
> Hi, all,
>
> On linux, I developed a little Tk animation using TkCanvas, and then I
> ran it on windows. It's much slower on windows than on linux (maybe,
> 5fps versus 30fps). Same machine, but ruby-1.8.4 on linux, 1.8.5 on
> windows.
>
> The Windows Task Manager says the process is only using a tiny fraction
> of cpu, so that's not the problem.
>
> The canvas is currently just about a dozen objects, nothing special
> (polygons, lines, etc.).
>
> It does have two threads, one doing Tk.mainloop, and one sending
> commands to the canvas. Increasing the priority of the command thread
> makes it worse: Tk doesn't even seem to run--no windows. Decreasing the
> priority makes it even slower.
>
> Nothing is waiting on terminal input (I know that's a problem on windows).
>
> I tried using a TkTimer instead, but couldn't get it to work at all.
...
Ok, I've got a workaround. I think the problem is that the command
thread (the one sending commands to the canvas) isn't getting enough
chances to run.
The workaround is to fire a very frequent task from the mainloop to
explicitly hand control to the command thread:
3.times do
timer = TkTimer.new(1) do
3.times {thread.run}
end
timer.start
end
The two threes was necessary on my system to get full CPU utilization.
Reducing either one of them resulted in using less CPU and having a
lower frame rate. The 1ms clock cycle also seems to be necessary.
With this workaround the animation runs at the same speed as on linux,
about 60fps. That's a lot better than the 6 fps without the hack.
I wish I knew whether this was a problem in ruby, tkruby, or windows...
Hope this helps someone else.
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407