Thanks for taking a look.

Unfortunately I was not targeting what is drawn, but how it is drawn. Think
100 colors instead of 2, in which case your optimization would gain only
1/100.  (I was just too lazy to actually create 100 brushes.)

I'm pretty sure this should not be as slow as that. (A quick and
non-accurate test in Java seems to suggest that it can be faster by several
orders of magnitude on this task. That would need to be verified though.)

On Thu, Jul 16, 2015 at 6:09 PM, Matthias Felleisen <matth...@ccs.neu.edu>
wrote:

>
> I conjecture method calls contribute to the expense. Here is a way to
> eliminate ~~ half the calls for the inner loop:
>
> (define (draw-to-dc dc)
>   (send dc set-pen no-pen)
>   (send dc set-brush brush-red)
>   (send dc draw-rectangle 0 0 XMAX YMAX)
>   (send dc set-brush brush-blue)
>   (for* ([x (in-range NUM-CELL-X)]
>          [y (in-range NUM-CELL-Y)]
>          #:when (= 0 (random 2)))
>     (send dc draw-rectangle (* x CELL-SIZE) (* y CELL-SIZE) CELL-SIZE
> CELL-SIZE)))
>
> It seems to run twice as fast but I don't have time to investigate. I am
> sure more savings are possible here (generic?).
>
> I do wonder whether the compiler coach could help here eventually.
> Relevant people CCed.
>
> -- Matthias
>
>
>
>
> On Jul 16, 2015, at 12:15 PM, Laurent <laurent.ors...@gmail.com> wrote:
>
> > I'm surprised by the slowness of animations in a canvas. Here's a simple
> stress test:
> > https://gist.github.com/Metaxal/73897e7bac5332054511
> >
> > For a 100x100 board it takes 2 seconds to draw 10 random frames (outside
> DrRacket of course). I was expecting at least 10x more frames per second.
> >
> > Is there anything that could speed this up substantially?
> >
> > Some notes:
> > - Using bigger cells (say size 10 instead of 2) has only a small impact
> on the performance
> > - Drawing directly to the canvas instead of using an intermediate buffer
> doesn't help (it's actually even worse because `refresh` may be called more
> than necessary)
> > - Replacing for* by let loops with additions and no multiplication makes
> no difference
> > - Creating the brushes outside the for loop is much faster (almost 1/3)
> than inside
> > - `draw-point` is quite slower than `draw-rectangle` for some reason
> > - displaying a random number in the terminal instead of selecting the
> brush and drawing the rectangle is twice faster
> > - I'm on Ubuntu 14.04, racket 6.1.1, 64bits
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to