I'm working on a sorting library for MArrays. Speed is important, so I want to optimize it as much as possible.
我正在为MArrays开发一个排序库。速度很重要,所以我想尽可能地优化它。
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.
目前,我只是INLINE的排序功能。与未优化的代码相比,这可以将代码加速10倍以上。但是,如果在多个位置使用这些函数,则很容易破坏代码大小,并且会降低编译速度。
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?
唯一的另一种选择似乎是对所有现有MArray实例的SPECIALIZE函数。这也会扩大生成的代码,但只能通过一个常数因子,这不取决于函数的使用次数。问题是,是否有可能出现新的MArray实例?或者是MArray如此特殊并且绑定到Haskell的内部,以便我可以确定其他模块不能定义任何新实例?
1 个解决方案
#1
3
Seems like that the best way is to use the INLINE
pragma. sort
from vector-algorithms uses it too.
似乎最好的方法是使用INLINE编译指示。从矢量算法排序也使用它。
#1
3
Seems like that the best way is to use the INLINE
pragma. sort
from vector-algorithms uses it too.
似乎最好的方法是使用INLINE编译指示。从矢量算法排序也使用它。