[GHC] #10108: Dramatic slowdown with -O2 bytestream and list streams combined.

#10108: Dramatic slowdown with -O2 bytestream and list streams combined. -------------------------------------+------------------------------------- Reporter: Truman | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.2 Component: Compiler | Version: 7.8.4 Keywords: | Operating System: Linux Architecture: | Type of failure: Runtime Unknown/Multiple | performance bug Test Case: | Blocked By: break_in.hs | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- In a small testcase intended to filter log files from stdin, I found that using bytestreams and list streams in combination worked fine when compiled without optimization, but runtime performance slowed down by a factor of about 3600 when I compiled with -O2. Changing the import of Data.List.Stream to Data.List gets rid of the problem. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10108 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10108: Dramatic slowdown with -O2 bytestream and list streams combined. -------------------------------------+------------------------------------- Reporter: Truman | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.2 Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | break_in.hs Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): Please can you say exactly which versions of which libraries are required? And the exact command line you used to compile `break_ins.hs`? This an awkward one. On the one hand, `ghc -O2` should not produce code 3600 time slower than `ghc -O`. On the the other hand, the example depends on two big libraries, each of which has lots of rewrite rules that may or may not be right. So there may be nothing wrong with GHC. It'd be really helpful if someone (e.g. the library maintainers) could investigate, and characterise more clearly what is going on. The more precisely the problem is identified, the more likely that someone will fix it. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10108#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10108: Dramatic slowdown with -O2 bytestream and list streams combined.
-------------------------------------+-------------------------------------
Reporter: Truman | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 7.10.2
Component: Compiler | Version: 7.8.4
Resolution: | Keywords:
Operating System: Linux | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | break_in.hs
Related Tickets: | Blocking:
| Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by Truman):
Sorry about not including the library information. I should have known
better.
Here is a log showing compiling non-optimized, running, compiling
optimized, and running again, that shows the runtime difference. I
shortened the input file (described above) to 5000 lines to speed things
up, but the problem is still clear.
The versions of the two seemingly relevant imports are:
bytestring-0.10.4.0
stream-fusion 0.1.2.5
The log files detail lots of other information.
I'm running GHC 7.8.4 under Arch Linux 3.19.2-1-ARCH, and I have tested
and confirmed this on both 32 and 64 bit machines.
I will attach the two verbose compilation log files.
CPC~/ghc_prob> touch break_ins.hs
CPC~/ghc_prob> ghc -v5 break_ins.hs >ghc_nopt.log 2>&1
CPC~/ghc_prob> time break_ins

#10108: Dramatic slowdown with -O2 bytestream and list streams combined. -------------------------------------+------------------------------------- Reporter: Truman | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.2 Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | break_in.hs Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): Interesting. The actual code in `Main` never gets very big, which is promising. Could you add `-ddump-rule-firings -ddump-simpl` to your command line and give the log files for that? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10108#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10108: Dramatic slowdown with -O2 bytestream and list streams combined. -------------------------------------+------------------------------------- Reporter: Truman | Owner: Type: bug | Status: closed Priority: normal | Milestone: 7.10.2 Component: Compiler | Version: 7.8.4 Resolution: invalid | Keywords: Operating System: Linux | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | break_in.hs Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by rwbarton): * status: new => closed * resolution: => invalid Comment: It's a bug or limitation in the stream-fusion package. This simpler program has the same problem: {{{ import qualified Data.List.Stream as SL bad_sum :: [Int] -> Int bad_sum xs = if null xs then 0 else head xs + bad_sum (SL.tail xs) main = print $ bad_sum [1..20000] }}} The reason is this rewrite rule for `SL.tail`: {{{ {-# RULES "tail -> fusible" [~1] forall xs. tail xs = unstream (Stream.tail (stream xs)) --"tail -> unfused" [1] forall xs. -- unstream (Stream.tail (stream xs)) = tail xs #-} }}} Note that the second rule is commented out! So each recursive call adds a layer of something similar to `foldr (:) []` to the remainder of the list, and the total time is quadratic. You might submit a bug report on stream-fusion, though I don't know whether it is still maintained. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10108#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10108: Dramatic slowdown with -O2 bytestream and list streams combined. -------------------------------------+------------------------------------- Reporter: Truman | Owner: Type: bug | Status: closed Priority: normal | Milestone: 7.10.2 Component: Compiler | Version: 7.8.4 Resolution: invalid | Keywords: Operating System: Linux | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | break_in.hs Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by rwbarton): (By the way, this was an issue of no optimizations versus -O2 (or -O), not -O versus -O2.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10108#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10108: Dramatic slowdown with -O2 bytestream and list streams combined. -------------------------------------+------------------------------------- Reporter: Truman | Owner: Type: bug | Status: closed Priority: normal | Milestone: 7.10.2 Component: Compiler | Version: 7.8.4 Resolution: invalid | Keywords: Operating System: Linux | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | break_in.hs Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): Thanks for investigating, Reid. Very helpful. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10108#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC