[plt-scheme] how to optimize my code ?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Apr 25 09:51:42 EDT 2009

At Fri, 24 Apr 2009 20:50:08 +0200, Ziboon wrote:
> My method to refresh my canvas:
> (define (start)
>   (set! PLAY #t)
>   (set! TH (thread (λ() (do () ((not PLAY))
>                                    (send my-canvas refresh)
>                                    (sleep/yield 0.001))))))

For what it's worth, in a thread that isn't the main thread,
`sleep/yield' is the same as `sleep'. It's ok to use `sleep/yield',

But 0.001 seconds is a very short time to sleep between demands to
refresh the canvas. Consider that your hardware only updates the
physical screen once every 0.01-0.02 seconds.

So, my guess is that your program stays too busy redrawing the canvas.
What happens if you change the 0.001 to 0.01 or even 0.1?

Posted on the users mailing list.