[GHC] #8457: -ffull-laziness does more harm than good

#8457: -ffull-laziness does more harm than good
------------------------------------+-------------------------------------
Reporter: errge | Owner:
Type: bug | Status: new
Priority: high | Milestone: 7.8.1
Component: Compiler | Version: 7.7
Keywords: | Operating System: Unknown/Multiple
Architecture: Unknown/Multiple | Type of failure: None/Unknown
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
------------------------------------+-------------------------------------
In this bug report I'd like to argue that `-ffull-laziness` shouldn't
be turned on automatically with either `-O` nor `-O2`, because it's
dangerous and can cause serious memory leaks which are hard to debug
or prevent. I'll also try to show that its optimization benefits are
negligible. Actually, my benchmarks show that it's beneficial to turn
it off even in the cases where we don't hit a space leak.
We've met this issue last week, but it had been reported several times
before: e.g. #917 and #5262.
A typical example is the following:
{{{
#!haskell
main :: IO ()
main = task () >> task ()
task :: () -> IO ()
task () = printvalues [1..1000000 :: Int]
printvalues :: [Int] -> IO ()
printvalues (x:xs) = print x >> printvalues xs
printvalues [] = return ()
}}}
We succeed with `-O0`, but fail with `-O`:
{{{
errge@curry:~/tmp $ ~/tmp/ghc/inplace/bin/ghc-stage2 -v0 -O0 -fforce-
recomp lazy && ./lazy +RTS -t >/dev/null
<

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------ Reporter: errge | Owner: Type: bug | Status: new Priority: high | Milestone: 7.8.1 Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by rwbarton): Very nice work! I just want to point out a [http://ghc.haskell.org/trac/ghc/ticket/7367#comment:7 suggestion] I made a little while ago, but haven't followed up on: it may be easy to identify certain occurrences of let-floating that are truly "safe" performance- wise, and control them with a separate flag, which would be on by default under `-O`. Then remove `-ffull-laziness` from `-O`. I would be interested to see the results of your experiment with such a patch. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------ Reporter: errge | Owner: Type: bug | Status: new Priority: high | Milestone: 7.8.1 Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by klao): * cc: mihaly.barasz@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------ Reporter: errge | Owner: Type: bug | Status: new Priority: high | Milestone: 7.8.1 Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): Interesting. But if I understand right this is just one program you are testing, namely GHC itself. Would you like to do a nofib run, with and without `-fno-full-laziness` and see what `nofib-analyse` says? thanks Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------ Reporter: errge | Owner: Type: bug | Status: new Priority: high | Milestone: 7.8.1 Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by akio): * cc: tkn.akio@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------ Reporter: errge | Owner: Type: bug | Status: new Priority: high | Milestone: 7.8.1 Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by errge): Hi Simon, Thanks for pointing me towards this 'Nestedly Organized Future Improving Benchmarks', they seem to be great. :) I followed http://ghc.haskell.org/trac/ghc/wiki/Building/RunningNoFib and the results are here: https://github.com/errge/notlazy/blob/master/nofib.txt There are some outliers in both directions, but the overall picture seems to me as kind of "nothing changing". Even more if you deduce the noise introduced by the outliers. It may be meaningful to have a look on fulsom, hidden, parser and parstof; these are the examples where the optimization did very good and it would be interesting to see whether it's easy to reintroduce the necessary sharing by hand. OTOH, I'm not really in the mood to debug thousand of lines of old school haskell written in '93 by academics. :-) If we get really bored, maybe will take a look... And there are some outliers on the negative side: constraints, bspt and integer. It'd be interesting to see here if the optimization introduced sharing or other performance bugs can is easy to workaround or not in these cases. My opinion about turning this off didn't change, but I can always just turn off myself, so feel free to either fix this or mark the bug as invalid. If there are more benchmarks to run, I'm happy to run them. Gergely -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------ Reporter: errge | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by errge): * priority: high => normal * milestone: 7.8.1 => 7.10.1 Comment: Also, I've changed the milestone now to 7.10.1 and changed the priority to normal. I don't want to rush anyone into a decision that is clearly not super important. Everything is like as it is for years, and users can easily say -fno-full-laziness themselves. Since this is only a simple flag switch, if we decide that we should do the switch, we can easily do it for 7.8.2 or later 7.8 releases, no rush. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------ Reporter: errge | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by simonpj): * cc: bos@…, johan.tibell@… (added) Comment: Thanks. A couple of `nofib` programs get a lot worse (eg `partsof` allocates 20x more), and the geometric mean of allocation I speculate that some of these extreme effects are because the programs have static data, but I'm not sure. The question is whether "typical" GHC users will see things getting better or worse. I'd be happy to know what our GHC Performance Tsars think (or indeed anyone else). Bryan, Johan: any views? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------ Reporter: errge | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by tibbe): I'd like to see an anlysis of the nofib outliers, both positive and negative, before making any changes. Once we know why they changed we can decide whether the benchmarks or the compiler are to blame. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------- Reporter: errge | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: Runtime | Blocked By: performance bug | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thomie): * failure: None/Unknown => Runtime performance bug -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------- Reporter: errge | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): See also #917, #1945, #3273, #4276, #5729, #10535 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------- Reporter: errge | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by edsko): * cc: edsko (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------- Reporter: errge | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #9520, #12620 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by edsko): * related: => #9520, #12620 Comment: Just published a blog post on the perils of full laziness when using conduit (see also #9520); it might be relevant to this ticket: http://www .well-typed.com/blog/2016/09/sharing-conduit/ . See also #12620 for a recent alternative proposal to limit the scope of full laziness. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------- Reporter: errge | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #9520, #12620 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by edsko): My blog post underestimated the perils of full laziness. Proposed erratum at https://www.reddit.com/r/haskell/comments/55xk4z/erratum_to_sharing_memory_l... . -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8457: -ffull-laziness does more harm than good -------------------------------------+------------------------------------- Reporter: errge | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: FloatOut Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #9520, #12620 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * keywords: => FloatOut -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8457#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC