Repository navigation
Conversation
Currently it is only in the benchmarks, but we should change the actual implementation as well. This commit also adds a benchmark for `findIndexR` that has to iterate the whole vector
|
Note that implementation differ in rather pathological case: Also benchmark is a bit pathological. It disallows inlining of predicate so GHC has to box value. I wonder how things will change if GHC get to see that predicate is strict and it could pass unboxed double. |
This benchmark is for unboxed vectors which can't store bottom. This means we could use this implementation for Unboxed, Primitive and Storable, but not for Boxed, which is already slower anyways. Am I wrong about this? None of the combinations of , bench "findIndexR_inlined" $ nf findIndexR_inline ( \ !x -> x < indexFindThreshold, as)findIndexR_inline :: (Double -> Bool, Vector Double) -> Maybe Int
{-# INLINE findIndexR_inline #-}
findIndexR_inline (pred, v) = go $ V.length v - 1
where go i | i < 0 = Nothing
| inline (pred (V.unsafeIndex v i)) = Just i
| otherwise = go $ i-1has the same performance as the one without any inlining on master. |
|
It doesn't change anything because However. If I allow partial application of predicate like: findIndexR :: (Double -> Bool) -> Vector Double -> Maybe Int
{-# INLINE findIndexR #-}
findIndexR_manual :: (Double -> Bool) -> Vector Double -> Maybe Int
{-# INLINE findIndexR_manual #-} , bench "findIndexR" $ nf (findIndexR (<indexFindThreshold)) asResults change drastically: I'm not sure why hand rolled loop performed so much worse. I didn't look into core. But it seems that performance gains of handrolled loop are highly situational |
|
Alright, than I think it makes sense to abandon this idea of optimizing @Shimuuar Thank you for investigating it a bit further! |
Currently it is only in the benchmarks, but we should change the actual implementation as well. This commit also adds a benchmark for
findIndexRthat has to iterate the whole vectorThis is the version from master: