The changelog for version 0.8 of vector lists the following change with a warning:
Functor, Monad, Applicative, Alternative, Foldable and Traversable instances for boxed vectors (WARNING: they tend to be slow and are only provided for completeness).
Could someone explain why this is the case? Is it just the normal cost of typeclass specialization, or something more interesting?
Update: Looking at some particular instances, one sees for example:
instance Foldable.Foldable Vector where
{-# INLINE foldr #-}
foldr = foldr
and similarly for the other folds. Does this mean that folding is slow for Vector
s in general? If not, what makes a non-specialized fold slow enough to warrant a warning?
I submitted the original set of these instances to Roman a year and a half ago and have maintained vector-instances since then. (I had to remove these instances from vector-instances once they migrated into vector, and now maintain it solely for the really exotic stuff). His concern was that if folks used these instances polymorphically then the RULES that make Vectors fuse away can't fire unless the polymorphic function gets inlined and monomorphized.
They exist because not every bit of code on the planet is Vector-specific and even then it is nice to sometimes use the common names.
Slow here is relative. The worst case is they perform like anybody else's folds, binds, etc. but Roman takes every single boxed value as a personal insult. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With