
#9339: last is not a good consumer -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.8.3 Keywords: | Differential Revisions: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- The profiler indicates that `print $ last [(1::Int)..10^7]` (compiled with -O2) allocates around 8*10^8 bytes. Using the Henning Thienemann-inspired {{{ myLast = fromJust . foldr (\x -> Just . maybe x id) Nothing }}} (based on his code for viewR/unsnoc) reduces allocation by about half at the cost of some extra work. What we really want, I believe, is for `last` to fuse with the producer in a fashion that allows the Ints to be unboxed, eliminating all the allocation. I have no idea if this will fall out of the general fusion work planned for 7.9. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9339 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler