Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly optimize MArray functions for speed?

I'm working on a sorting library for MArrays. Speed is important, so I want to optimize it as much as possible.

Currently, I simply INLINE the sorting functions. This speeds up the code more than 10 times, compared to the non-optimized code. However this can easily explode code size if the functions are used in several places, and slows down compilation.

The only other alternative seems to SPECIALIZE the functions for all existing instances of MArray. This also enlarges the resulting code, but only by a constant factor, which doesn't depend on how many times the functions are used. The question is, is it possible that new instances of MArray appear? Or is MArray so special and bound to Haskell's internals so that I can be sure that no new instances can be defined by some other module?

like image 883
Petr Avatar asked Jan 15 '13 08:01

Petr


1 Answers

Seems like that the best way is to use the INLINE pragma. sort from vector-algorithms uses it too.

like image 57
Petr Avatar answered Nov 15 '22 19:11

Petr