Skip to content

last is not a good consumer

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.

Trac metadata
Trac field Value
Version 7.8.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC ekmett, hvr
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information