
#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 dfeuer): Replying to [comment:1 nomeata]:
What general fusion work are you referring to? I only know about the improvements for fusing foldl, which doesn’t seem to apply here.
I was under the impression (possibly bogus) that the `foldl` fix involved some new transformation that could have other effects.
Although maybe it could. How about this definition:
{{{ myLast2 :: [a] -> a myLast2 = foldl (\_ x -> x) undefined }}}
While `last` yields 800051648 bytes, and `myLast` yields 560084432 bytes, this runs in 51648 bytes (i.e. it fuses completely).
That looks wonderful. Is it certain to be changed to a `foldl'` in cases where it ''doesn't'' fuse?
Admitted, the resulting code looks almost stupidly efficient (at least if I write `10^7` as `10000` – I’m unjustifiably surprised that that is not constant-folded):
Imagine the confusion if it were! Yes, `map f [m..n] !! p` ''could'' be optimized to O(1) whenever `m` has a known-sane type, but then all the newbies and half the oldies would get mixed up when little changes had radical performance impacts. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9339#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler