
#9339: last is not a good consumer
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: | Version: 7.8.3
libraries/base | Keywords:
Resolution: | Operating System: Unknown/Multiple
Differential Revisions: | Type of failure: Runtime
Architecture: | performance bug
Unknown/Multiple | Test Case:
Difficulty: Unknown | Blocking:
Blocked By: |
Related Tickets: |
-------------------------------------+-------------------------------------
Comment (by nomeata):
Ok, let’s do this systematically.
My benchmarks: One possibly fusing invocation of `last`:
{{{
main = print $ Last.last $ filter odd $ [1::Int ..100000000]
}}}
and one non-fusing
{{{
f = id
{-# NOINLINE f #-}
main = print $ Last.last $ f $ filter odd $ [1::Int ..100000000]
}}}
I am comparing the existing implementation of `last`, which is
{{{
last [] = errorEmptyList "last"
last (x:xs) = last' x xs
where last' y [] = y
last' _ (y:ys) = last' y ys
}}}
with the simpler
{{{
last = foldl (\_ x -> x) (errorEmptyList "last")
}}}
Just for fun (and because GHC HEAD still compiles), here the numbers with
GHC-7.6:
{{{
LastTestFusing.hs
<