
#12996: Memory leak in recursion when switching from -O1 to -O2 -------------------------------------+------------------------------------- Reporter: AndreasK | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Memory leak, | optimization 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 osa1): I analyzed this a little bit, here's my findings: - The function that causes this slowness is generated by `SpecConstr`. If you compile with `-O2 -fno-spec-constr` it works fine. - When `appLoop` function is defined like this: {{{#!haskell appLoop :: AppState -> IO () appLoop s = do let AppState state = s print state appLoop $ AppState (cycleState state) }}} Demand analyzer thinks `appLoop` is not strict on `s`. If we define it like this: {{{#!haskell appLoop :: AppState -> IO () appLoop (AppState state) = do print state appLoop $ AppState (cycleState state) }}} Worker/wrapper runs instead of SpecConstr and this version compiles to fast code. I don't understand why `-O2` version is getting slower in each iteration, but I suspect it has do to with Cmm rather than STG. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12996#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler