[GHC] #16190: Speed up handling of large String literals

GHC ghc-devs at haskell.org
Thu Jan 17 10:07:06 UTC 2019


#16190: Speed up handling of large String literals
-------------------------------------+-------------------------------------
        Reporter:  hsyl20            |                Owner:  (none)
            Type:  task              |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.6.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by hsyl20):

 I have experimented with this in the following branch:
 https://gitlab.haskell.org/hsyl20/ghc/tree/hsyl20-T16190

 It adds a GHC command-line flag to choose the threshold (in bytes) above
 which the strings are dumped in a binary file (e.g. `./inplace/bin/ghc-
 stage2 -fbinary-string-threshold=200`).

 The current implementation performs the transformation in the tidy pass.
 I'm not sure if it is the best place to do it.

 The included `bench_literal.sh` script generates an Haskell source file
 which prints a string literal and then benches the time required to
 compile it. Below are the results for different string lengths. With this
 test, the optimization starts to be really noticeable for string literals
 >500K.

 || Size || No optimization || Threshold 100 || Gain ||
 || 128  || 0.730           || 0.770         || -5%  ||
 || 3K   || 0.731           || 0.829         || -13% ||
 || 30K  || 0.736           || 0.805         || -9%  ||
 || 100K || 0.804           || 0.856         || -6%  ||
 || 500K || 1.038           || 0.912         || +12% ||
 || 1M   || 1.342           || 1.101         || +18% ||
 || 2M   || 1.926           || 1.446         || +25% ||
 || 3M   || 2.539           || 1.805         || +29% ||
 || 30M  || 20.182          || 10.244        || +49% ||

 I couldn't test with TH generated string literals as it crashes the
 compiler because some names become garbage with the optimization enabled.
 We should probably only enable the optimization if we generate an actual
 linked object file. It isn't done yet.

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


More information about the ghc-tickets mailing list