[GHC] #10825: Poor performance of optimized code.

#10825: Poor performance of optimized code. -------------------------------------+------------------------------------- Reporter: AndriusS | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Runtime Unknown/Multiple | performance bug Test Case: | Blocked By: Blocking: | Related Tickets: #8814, #8835 Differential Revisions: | -------------------------------------+------------------------------------- This is possible duplicate of #8814, #8835. I am creating new ticket as I have fairly small example with no dependencies. The problem is that optimized code runs orders of magnitude slower than non-optimized. {{{#!hs import System.IO.Unsafe (unsafePerformIO) newtype MyList = MyList Int equalsLast :: MyList -> Int -> Bool equalsLast (MyList value) = (== value) fromList :: [Int] -> MyList fromList = MyList . last {- minimizing imports -} (<$>) = fmap replicateM' n x = sequence (replicate n x) readInt = read <$> getLine :: IO Int readAndMap :: Int -> (Int->Bool) -> IO [Bool] readAndMap n f = replicateM' n (f <$> readInt) {- if readAndMap is replaced by commented out line below, the problem goes away -} --readAndMap n f = map f <$> replicateM' n (readInt) fromList' :: [Int] -> MyList {- an attempt to further demostrate the issue. fromList'=fromList is very slow as well -} fromList' list = unsafePerformIO $ do putStrLn "fromList" return $ fromList list readMyList :: Int -> IO MyList readMyList n = fromList' <$> (replicateM' n $ read <$> getLine) main :: IO () main = do n1 <- read <$> getLine :: IO Int n2 <- read <$> getLine :: IO Int l <- readMyList n1 ans <- readAndMap n2 (equalsLast l) mapM_ print ans }}} If this code is compiled with no flags, it prints "fromList" once and runs in 0.3s. Compiled with "-O" prints "fromList" many times and takes over 6 seconds. Here's a Haskell script to generate input for program above: {{{#!hs main = sequence_ $ map print (n:n:[1..n]++[1..n]) where n = 10000 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10825 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10825: Poor performance of optimized code. -------------------------------------+------------------------------------- Reporter: AndriusS | Owner: bgamari Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #8814, #8835 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by bgamari): * owner: => bgamari Comment: Ooh, this looks like a very nice case to put on my performance-related- issues queue. Thanks for the small testcase. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10825#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10825: Poor performance of optimized code. -------------------------------------+------------------------------------- Reporter: AndriusS | Owner: bgamari Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #8814, #8835 | Differential Revisions: -------------------------------------+------------------------------------- Comment (by rwbarton): Does `-fno-state-hack` make a difference? Since I see `replicateM` stuff. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10825#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10825: Poor performance of optimized code. -------------------------------------+------------------------------------- Reporter: AndriusS | Owner: bgamari Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #8814, #8835 | Differential Revisions: -------------------------------------+------------------------------------- Comment (by AndriusS): Yes, with `-fno-state-hack` everything works fine. This is probably a duplicate of #1168. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10825#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10825: Poor performance of optimized code. -------------------------------------+------------------------------------- Reporter: AndriusS | Owner: bgamari Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: duplicate | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #1168 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by thomie): * status: new => closed * resolution: => duplicate * related: #8814, #8835 => #1168 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10825#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC