Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#5317 closed bug (wontfix)

non-linear complexity of :reload combined with :module in ghci

Reported by: SimonHengel Owned by:
Priority: normal Milestone: 7.4.1
Component: Compiler Version: 7.0.3
Keywords: Cc: simon.hengel@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


ghci shows non-linear time complexity for a sequence of :module and :reload commands, say we do multiple times:

ghci> :module *Foo
ghci> :reload

Steps to reproduce:

$ time for i in {1..10}; do echo -e ':m Prelude\n:r'; done |ghci
$ time for i in {1..99}; do echo -e ':m Prelude\n:r'; done |ghci

On my system the first run uses 1 second of CPU time, the second 39 seconds.

(with GHC 7.0.3, Linux x86_64)

Change History (3)

comment:1 Changed 6 years ago by igloo

Milestone: 7.4.1

I can reproduce this with the 7.0.2 amd64/Linux bindist:

7.0 10:      0.49s user
7.0 100:    17.69s user

My 7.2 validate is a lot faster (I'd guess due to something like not having split objects), but is still non-linear:

7.2 1000:    3.89s user
7.2 10000: 218.63s user

comment:2 Changed 6 years ago by simonmar

Resolution: wontfix
Status: newclosed

It's faster in 7.2 as a result of my changes in 5cd39aa33f970ff42e22b1c9c73502e4229dc488

Author: Simon Marlow <>
Date:   Sat Jun 4 00:13:04 2011 +0100

    Tidy up the ic_exports field of the InteractiveContext.  Previously
    was [(Module, Maybe ImportDecl)], now it is just [ImportDecl].  So now
    ":m +A" and "import A" do exactly the same thing in GHCi, and use the
    same code paths.

The underlying problem remains, but is far less severe now. The problem is this: we keep track of all the :module and import commands and replay them after each :reload. The list is cleared by :load and a few other things. It's not obvious to me if there's a good way to tell in general when you can remove items from the list.

I'm tempted to just punt on this. It won't be nearly as noticeable in 7.2 anyway.

comment:3 Changed 6 years ago by marlowsd@…

commit 79d6745f66c678de5e104b2146d3dd3e2f006c3e

Author: Simon Marlow <>
Date:   Fri Aug 26 16:36:05 2011 +0100

    Clean up the handling of the import and :module commands in GHCi
    Previously we remembered the whole history of commands and replayed
    them on every :load/:reload, which lead to some non-linear performance
    characteristics (#5317).  The handling of the implicit Prelude import
    and the implicit imports of recently loaded modules was also
    complicated and wrong in various obscure ways.
    The Prelude import works just like the implicit Prelude import in a
    Haskell module: it can be overriden with an explicit Prelude
    I have added a new ":show imports" command to show which imports are
    currently in force.
    Prelude> :show imports
    import Prelude -- implicit
    Prelude> import Prelude ()
    Prelude> :show imports
    import Prelude ()
    Prelude> map
    <interactive>:0:1: Not in scope: `map'
    Full documentation in the User's Guide.
    There are various other little tweaks and improvements, such as when a
    module is imported with 'as', we now show the 'as' name in the prompt
    rather than the original name.

 compiler/hsSyn/HsImpExp.lhs |    2 +-
 docs/users_guide/ghci.xml   |  135 ++++++---
 ghc/GhciMonad.hs            |   39 ++--
 ghc/InteractiveUI.hs        |  733 +++++++++++++++++++++++++------------------
 4 files changed, 543 insertions(+), 366 deletions(-)
Note: See TracTickets for help on using tickets.