Opened 12 years ago

Closed 12 years ago

Last modified 21 months ago

#1945 closed bug (duplicate)

Full laziness is sometimes a pessimisation

Reported by: jleedev Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.8.1
Keywords: FloatOut Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I've found a case where the optimizer produces code that uses more memory and runs slower. Here's an example that contrasts the default behavior with the optimized behavior. Cale posted a comparison of GHC's core on this program (using 6.8.1) on http://hpaste.org/4133#a1.

Without optimizations: Both print statements take the same (fairly short) amount of time.
With optimizations: The first print statement takes a lot longer, but second happens very quickly.

Essentially, it is caching the entire 10 million item list, instead of just its length.

$ cat test.hs 
f x = length [0 .. x :: Int]
main = do
    print $ f 10000000
    print $ f 10000000
$ time runhaskell test.hs 
10000001
10000001

real    0m0.682s
user    0m0.636s
sys     0m0.044s
$ ghc --make test
[1 of 1] Compiling Main             ( test.hs, test.o )
Linking test ...
$ time ./test 
10000001
10000001

real    0m0.438s
user    0m0.428s
sys     0m0.008s

$ rm test test.hi test.o
$ ghc --make test -O
[1 of 1] Compiling Main             ( test.hs, test.o )
Linking test ...
$ time ./test 
10000001
10000001

real    0m2.447s
user    0m2.200s
sys     0m0.224s

Change History (4)

comment:1 Changed 12 years ago by simonmar

difficulty: Unknown
Resolution: duplicate
Status: newclosed
Summary: Faulty optimizationsFull laziness is sometimes a pessimisation

Thanks for reporting, but this is long-standing issue, see #917. -fno-full-laziness is your friend.

comment:2 Changed 11 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:3 Changed 11 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:4 Changed 21 months ago by simonpj

Keywords: FloatOut added
Type of failure: None/Unknown
Note: See TracTickets for help on using tickets.