首页 > 解决方案 > 在没有配置文件构建的情况下确定高 GHC 内存消耗的原因

问题描述

我听说 GHC 在每秒 LOC 方面很慢。所以我创建了这个 Haskell 程序:

module Main where
x1 = 1
x2 = 2
x3 = 3
...
x999998 = 999998
x999999 = 999999
x1000000 = 1000000
main = putStrLn "1M LOC!"

我什至不能编译它!至少我可以看到解析器每秒可以执行 43 行:

[1 of 1] Compiling Main             ( 1Mloc.hs, 1Mloc.o )
*** Parser [Main]:
Parser [Main]: alloc=22735369056 time=23683.420

据我所知,必须重新编译 GHC RTS 并启用分析才能开始挖掘原因。鉴于我没有分析 GHC,有没有机会找出导致这种情况的原因?我什至无法收集统计数据,因为它被杀死了......

Killed process 16609 (ghc) total-vm:1074093288kB, anon-rss:6804448kB ...

实际上,我也无法编译 10K LOC。至少在 1K LOC 的情况下,我可以看到可怕的生产力数字。我意识到这是一个合成程序,但它有什么不好的呢?

Linking 1Kloc ...
   1,383,344,416 bytes allocated in the heap
     325,164,408 bytes copied during GC
      60,849,840 bytes maximum residency (9 sample(s))
         282,960 bytes maximum slop
              58 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0       233 colls,     0 par    0.227s   0.230s     0.0010s    0.0066s
  Gen  1         9 colls,     0 par    0.149s   0.174s     0.0193s    0.0588s

  TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)

  SPARKS: 0(0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.000s  (  0.000s elapsed)
  MUT     time    0.522s  (  1.047s elapsed)
  GC      time    0.376s  (  0.404s elapsed)
  EXIT    time    0.000s  (  0.008s elapsed)
  Total   time    0.899s  (  1.460s elapsed)

  Alloc rate    2,647,974,824 bytes per MUT second

  Productivity  58.1% of total user, 71.7% of total elapsed

标签: ghc

解决方案


推荐阅读