I try to use Gloss.Raster.Array
to effectively plot a set of points on a screen. It uses an Array D DIM2 Color
as a container of points to plot. Currently it is a 500x500 array, representing a 'bitmap'.
Suppose that each frame I generate 1 new point to display.
I didn't find another way to adjust an existing repa array to contain a single new point rather than doing repa's traverse
which looks approximately like this:
{-# INLINE traverseFn #-}
traverseFn px py = (\lookupfn i@(Z :. x :. y) ->
if x == px && y == py then red else lookupfn i)
newarr px py = R.traverse oldarr id (traverseFn px py)
I suspected this could turn to be rather inefficient: traversing whole 500x500 array for the sake of one point. But I thought maybe ghc will do some optimization magic and it won't.
Turns out it is. I tried to profile and it says that newarr
takes 97.2% of time. And it works very slow too.
I'm kinda new to the whole haskell and repa ecosystem, taking my first steps, so I might not know something or do something wrong (either in my repo code or in my profiling attempts) - hence asking for help :)
Is there some performant way to change single value in repa array on each frame? Or if I want to add 500 points on each frame - what would be the answer then?