[GHC] #10067: The Read Integer instance is too slow

GHC ghc-devs at haskell.org
Fri Feb 13 17:24:43 UTC 2015


#10067: The Read Integer instance is too slow
-------------------------------------+-------------------------------------
        Reporter:  redneb            |                   Owner:
            Type:  feature request   |                  Status:  patch
        Priority:  high              |               Milestone:  7.10.1
       Component:  Core Libraries    |                 Version:  7.11
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:  Phab:D645
-------------------------------------+-------------------------------------

Comment (by redneb):

 So let me explain what the problem is. My patch modifies the module
 `Text.Read.Lex`. This module defines among other thinks a `ReadP` parser
 that is used to implement the `Read` instances of all integral types. The
 actual instances though, are given in `GHC.Read` (except for `Natural` of
 course). My patch works by providing an optimized version of an
 ''internal'' function of `Text.Read.Lex`. If we also want to provide a
 version of that function for `Natural`, then we need to import
 `GHC.Natural`. But this creates multiple import cycles, exactly because
 that module was designed to be a leaf module. Namely, all of the following
 imports of `GHC.Natural` are problematic: `GHC.Read`, `Data.Data`,
 `GHC.Exception`, `Data.Int`, and `Data.Word`. So now we have 3 options:

 1. Use my patch as it is, without the `Natural` specialization. Remeber
 that the `Read Natural` instance relies on the `Read Integer` instance and
 it will benefit too from my patch.
 1. Use a simple hs-boot file for `GHC.Natural`.
 1. Break the cycle by moving stuff out of `GHC.Natural`. This requires
 extensive changes (just look at the list of offending imports above) and
 honestly, my patch is not the only thing in `base` that does not treat
 `Natural` as an equal to `Integer` right now; for example the `Show
 Integer` has an ad-hoc implementation that has not been extended for
 `Natural` (instead `Show Natural` relies on `Show Integer` again).
 Given all of the above, I think 2 is the best option here. I really don't
 like hs-boot files, but I do think that the way `Natural`s have been
 implemented and possible large scale changes to that, is largely unrelated
 to my patch and should be discussed separately.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10067#comment:10>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list