
#9520: Running an action twice uses much more memory than running it once -------------------------------------+------------------------------------- Reporter: snoyberg | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime | Difficulty: Unknown performance bug | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by int-e): Replying to [comment:4 snoyberg]: Without looking at the core, {{{sinkCount}}} has the potential to become a large shared data structure, if the {{{loop $! cnt + 1}}} part is floated out like so: {{{ sinkCount :: Sink i Int sinkCount = loop 0 where loop cnt = let sink' = loop $! cnt + 1 in Sink (\_ -> sink') cnt }}} Then the run-time representation of {{{(\_ -> sink')}}} is a closure that points to the next sink, {{{sink'}}}. The first time {{{sinkCount}}} is used it'll produce many sinks {{{(Sink (\_ -> sink') cnt)}}} for increasing counts, each linking to the next. Ideally, {{{sinkCount}}} and {{{feed}}} should be fused, but that requires inlining parts of {{{sinkCount}}} which given its recursive definition is tricky. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9520#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler