
Claus Reinke wrote:
i never quite understood why DiffArrays are so slow at the moment, so perhaps this is a good opportunity to ask for enlightenment on this issue?-)
it seems i should qualify that. some simple-minded testing shows that DiffArrays do become faster than Arrays if the arrays get big enough. for small arrays, though, just copying the Array seems faster than maintaining the DiffArray. copying then discarding old arrays can be cheaper than the overhead associated with avoiding copies.
Looking at the implementation of DiffArrays, there are some obvious optimisations that aren't done. UNPACKing everything in sight would be a good start. I guess this code has never really had a performance evaluation done on it. DiffUArray stores the array unboxed, but the difference elements are stored boxed, as far as I can tell. That means extra unnecessary allocation for each update. Also the indices are stored boxed - there's no reason to do that for either kind of DiffArray. All the operations are wrapped in unsafePerformIO, which is far from optimal (unsafePerformIO is not inlined, we should use inlinePerformIO if possible). Would someone like to shake this library into shape? I bet there's a significant performance win to be had. Cheers, Simon