[GHC] #14741: High-memory usage during compilation using Template Haskell

GHC ghc-devs at haskell.org
Tue Feb 6 06:39:44 UTC 2018


#14741: High-memory usage during compilation using Template Haskell
-------------------------------------+-------------------------------------
        Reporter:  donatello         |                Owner:  sighingnow
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Compile-time      |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D4384
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by sighingnow):

 * owner:  (none) => sighingnow
 * failure:  None/Unknown => Compile-time performance bug
 * differential:   => Phab:D4384


Comment:

 After profiling, I found that the `pprASCII` function consumed the most
 part of memory.


 {{{
 codeOutput                                    HscMain
 compiler\main\HscMain.hs:(1349,19)-(1350,67)       1863          2    0.1
 0.0    84.6   94.3
  OutputAsm                                    CodeOutput
 compiler\main\CodeOutput.hs:(169,37)-(171,78)      1873          2    0.2
 0.0    84.6   94.3
   NativeCodeGen                               CodeOutput
 compiler\main\CodeOutput.hs:171:18-78              1874          2    0.0
 0.0    84.3   94.3
    cmmNativeGenStream                         AsmCodeGen
 compiler\nativeGen\AsmCodeGen.hs:(342,56)-(343,50) 1875          2    0.0
 0.0    84.3   94.3
     cmmNativeGens                             AsmCodeGen
 compiler\nativeGen\AsmCodeGen.hs:(432,53)-(433,66) 1886         21    0.0
 0.0    80.3   87.8
      pprNativeCode                            AsmCodeGen
 compiler\nativeGen\AsmCodeGen.hs:(530,37)-(531,65) 1891        109   43.9
 22.3    51.5   30.3
       x86_pprNatCmmDecl_CmmData               X86.Ppr
 compiler\nativeGen\X86\Ppr.hs:78:43-82             1901          0    0.1
 0.0     7.5    8.0
        pprDataItem'                           X86.Ppr
 compiler\nativeGen\X86\Ppr.hs:477:76-98            1910        124    0.0
 0.0     0.0    0.0
         pprDataItem'_vcat                     X86.Ppr
 compiler\nativeGen\X86\Ppr.hs:481:37-95            1911        124    0.0
 0.0     0.0    0.0
        pprData_CmmString                      X86.Ppr
 compiler\nativeGen\X86\Ppr.hs:152:36-90            1903          0    0.0
 0.0     7.5    8.0
         pprASCII                              X86.Ppr
 compiler\nativeGen\X86\Ppr.hs:199:28-62            1905          0    7.5
 8.0     7.5    8.0
       x86_pprNatCmmDecl_CmmProc               X86.Ppr
 compiler\nativeGen\X86\Ppr.hs:(81,43)-(113,26)     1965          0    0.0
 0.0     0.1    0.0
        pprDataItem'                           X86.Ppr
 compiler\nativeGen\X86\Ppr.hs:477:76-98            1968        122    0.0
 0.0     0.0    0.0
         pprDataItem'_vcat                     X86.Ppr
 compiler\nativeGen\X86\Ppr.hs:481:37-95            1969        122    0.0
 0.0     0.0    0.0
      seqString                                AsmCodeGen
 compiler\nativeGen\AsmCodeGen.hs:505:33-95         1908        109    0.0
 0.0     0.0    0.0
      x86_pprNatCmmDecl_CmmData                X86.Ppr
 compiler\nativeGen\X86\Ppr.hs:78:43-82             1900         85    0.0
 0.0    28.6   57.3
       pprData_CmmString                       X86.Ppr
 compiler\nativeGen\X86\Ppr.hs:152:36-90            1902         66    0.0
 0.0    28.6   57.3
        pprASCII                               X86.Ppr
 compiler\nativeGen\X86\Ppr.hs:199:28-62            1904         66   28.6
 57.3    28.6   57.3
 }}}

 The embed bytestring generates a large literal bytestring in assembly
 code, represented by `(CmmString [Word8])`. The `pprASCII` function will
 generated a list of Lit SDoc then use `hcat` to combine them.

 I have made some optimization to `pprASCII` in Phab:D4384, after this
 patch this `pprASCII` still consume the most part of memory allocation,
 but it can decrease the total memory allocation efficiently.

 Before:

 {{{
 total time  =        2.43 secs   (2429 ticks @ 1000 us, 1 processor)
 total alloc = 4,741,422,496 bytes  (excludes profiling overheads)
 }}}

 After:


 {{{
 total time  =        0.85 secs   (851 ticks @ 1000 us, 1 processor)
 total alloc = 1,343,531,416 bytes  (excludes profiling overheads)
 }}}

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


More information about the ghc-tickets mailing list