
#14208: Performance with O0 is much better than the default or with -O2, runghc performs the best -------------------------------------+------------------------------------- Reporter: harendra | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 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: | -------------------------------------+------------------------------------- Comment (by simonpj): This is odd. I can't reproduce what you are seeing. I get this, measuring allocation {{{ HEAD, separate modules, but with {-# INLINABLE #-} on toList -O0 496M -O1 160M -O1 -fno-pre-inlining 312M HEAD, One module -O0 496M -O1 160M -O1 -fno-pre-inlining 312M GHC-8.2-branch, one module -O0 496M -O1 160M -O1 -fno-pre-inlining 312M }}} Here's the code I'm using (I had to add `instance Semigroup (List a)`: {{{ module Main where import Control.Monad (liftM) import Data.Semigroup (Semigroup(..)) -- import T14208a ------------------------------- data List a = Stop | Yield a (List a) instance Monoid (List a) where mempty = Stop mappend x y = case x of Stop -> y Yield a r -> Yield a (mappend r y) instance Semigroup (List a) where (<>) = mappend toList :: Monad m => List a -> m [a] toList m = case m of Stop -> return [] Yield a r -> liftM (a :) (toList r) -------------------------------- len :: IO Int len = do xs <- toList $ (foldr mappend mempty $ map (\x -> Yield x Stop) [1..1000000 :: Int]) return (length xs) main = do { x <- len; print x } }}} With "two files" I pushed the stuff between the lines into a separate file. I did an an INLINABLE pragma for `toList`. And I multiplied the limit count by 10. I did not use Criterion (less to depend on). Can you say more precisely how to reproduce the problem? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14208#comment:22 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler