[GHC] #15519: Minor code refactoring leads to drastic performance degradation

GHC ghc-devs at haskell.org
Wed Aug 29 12:27:53 UTC 2018


#15519: Minor code refactoring leads to drastic performance degradation
-------------------------------------+-------------------------------------
        Reporter:  danilo2           |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  highest           |            Milestone:  8.8.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:  SpecConstr
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by simonpj):

 * keywords:   => SpecConstr


Comment:

 OK, re comment:12, this is an old problem: see Trac #4448.   The current
 (horrible) solution is to take control explicitly, like this
 {{{
 import GHC.Type( SPEC(..) )

 runTokenParser :: SPEC -> Grammar Char -> Text -> Result
 runTokenParser = \sp grammar stream -> case grammar of
     Tokens _ tst -> let
         head = Text.head stream
         in if tst head
             then Success (Text.tail stream) (Text.singleton head)
             else Fail
     Many (Tokens _ tst) -> let
         (!consumed, !rest) = Text.span tst stream
         in Success rest consumed
     X !grammar -> runTokenParser sp grammar stream
 }}}
 Notice that `SPEC` argument. It's not actually used, but it tells
 `SpecConstr` to specialise the call regardless of whether the function
 scrutinises the argument (see Trac #4448 for a simpler example).

 That indeed makes `test2` work nicely.  I don't claim that it's nice.  At
 all.

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


More information about the ghc-tickets mailing list