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

GHC ghc-devs at haskell.org
Fri Aug 7 14:10:06 UTC 2015


#10067: The Read Integer instance is too slow
-------------------------------------+-------------------------------------
        Reporter:  redneb            |                   Owner:
            Type:  feature request   |                  Status:  closed
        Priority:  normal            |               Milestone:  7.12.1
       Component:  Core Libraries    |                 Version:  7.11
      Resolution:  fixed             |                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
-------------------------------------+-------------------------------------
Changes (by bgamari):

 * priority:  high => normal
 * status:  new => closed
 * resolution:   => fixed


Comment:

 As far as I can tell the critical issue of quadratic parsing of integers
 is by Phab:D645, which has been merged. The only work that remains here is
 to specialize for `Natural` but as Edward points out this is now a
 reasonable cheap operation as we can show,
 {{{#!hs
 import GHC.Natural
 import Criterion.Main

 main = defaultMain
     [ bench "integer" $ nf (read :: String -> Integer) (take 1000000 $
 cycle "1234567890")
     , bench "natural" $ nf (read :: String -> Natural) (take 1000000 $
 cycle "1234567890")
     ]
 }}}

 {{{
 $ ghc Test.hs -O -fforce-recomp
 [1 of 1] Compiling Main             ( Test.hs, Test.o )
 Linking Test ...
 $ ./Test
 benchmarking integer
 time                 435.5 ms   (410.6 ms .. 484.4 ms)
                      0.998 R²   (0.997 R² .. 1.000 R²)
 mean                 441.3 ms   (434.3 ms .. 445.5 ms)
 std dev              6.383 ms   (0.0 s .. 7.230 ms)
 variance introduced by outliers: 19% (moderately inflated)

 benchmarking natural
 time                 428.2 ms   (415.5 ms .. 446.6 ms)
                      1.000 R²   (1.000 R² .. 1.000 R²)
 mean                 434.6 ms   (432.0 ms .. 436.0 ms)
 std dev              2.261 ms   (0.0 s .. 2.387 ms)
 variance introduced by outliers: 19% (moderately inflated)
 }}}


 For this reason I"m going to close this issue..

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


More information about the ghc-tickets mailing list