[GHC] #15503: interpreter: sequence_ (replicate 100000000 (return ())) gobbles up memory
GHC
ghc-devs at haskell.org
Sun Sep 23 13:35:18 UTC 2018
#15503: interpreter: sequence_ (replicate 100000000 (return ())) gobbles up memory
-------------------------------------+-------------------------------------
Reporter: int-e | Owner: osa1
Type: bug | Status: new
Priority: high | Milestone: 8.8.1
Component: GHCi | Version: 8.5
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):
Hmm. Thanks for showing the full code that GHCi compiles
to bytecode. It looks like this:
{{{
let main_action = ...
in bindIO main_action (\it -> return [it])
}}}
So GHCi will build a thunk for `main_action` and will pass it
to the compiled code for `GHC.Base.bindIO`.
But alas `main_action` is essentially this
{{{
main_action :: IO ()
main_action = sequence_ (replicate ...)
}}}
(I have omitted the `ghcStepIO` stuff; it is essentially the
identity function, and I don't think it affects things.)
Now that `main_action` thunk will be updated, so if it
remains live for any reason, we'll retain a huge PAP
of the form described in an earlier comment `return () >> (return ()
...))`.
Why is it being kept alive? I'm really not sure. The interpreter
should be ''tail-calling'' `bindIO`...
I wonder if `main_action` could be floated to top level as a CAF
before it gets to the bytecode generator?
Anyway, I hope that may help a bit.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15503#comment:12>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list