haskell / haddock

Haskell Documentation Tool
www.haskell.org/haddock/
BSD 2-Clause "Simplified" License
361 stars 241 forks source link

Use the `Builder` patch for `xhtml` #1546

Closed parsonsmatt closed 1 year ago

parsonsmatt commented 1 year ago

This PR uses the Builder patch to the xhtml library.

Performance comparison was done in a similar manner to the CPS WriterT patch, notes on the xhtml PR.

tl;dr:

While it seems kinda funny to care too much about "oh wow 600ms to 300ms wow wow", we've got some big re-export modules at work that currently take 33 seconds to generate, and ppHtml allocates over 800GB.

EDIT:

Correctness

OK, I've tested the Haddock generation by building haddock with this patch and with the ghc-9.4 branch. The generated HTML is identical, as tested by diff.

Performance

This time I'm using persistent instead of persistent-test because it has fewer steps to get perf output from.

Haddock ghc-9.4

This is built using haddock on the ghc-9.4 branch.

ppHtml: alloc=1134416896 time=380.667
  15,979,133,408 bytes allocated in the heap
   2,437,895,544 bytes copied during GC
     238,259,312 bytes maximum residency (15 sample(s))
       5,391,248 bytes maximum slop
             554 MiB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0      3797 colls,     0 par    1.224s   1.226s     0.0003s    0.0031s
  Gen  1        15 colls,     0 par    0.875s   0.876s     0.0584s    0.1627s

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

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

  INIT    time    0.001s  (  0.000s elapsed)
  MUT     time    4.660s  (  5.192s elapsed)
  GC      time    2.099s  (  2.101s elapsed)
  EXIT    time    0.001s  (  0.007s elapsed)
  Total   time    6.761s  (  7.300s elapsed)

  Alloc rate    3,428,870,682 bytes per MUT second

  Productivity  68.9% of total user, 71.1% of total elapsed

Documentation created:
/home/matt/Projects/persistent/dist-newstyle/build/x86_64-linux/ghc-9.4.3/persistent-2.14.4.3/doc/html/persistent/index.html

xhtml Builder

ppHtml: alloc=1140800792 time=197.762
  15,973,532,640 bytes allocated in the heap
   2,222,376,616 bytes copied during GC
     195,984,808 bytes maximum residency (14 sample(s))
       5,124,696 bytes maximum slop
             466 MiB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0      3727 colls,     0 par    1.203s   1.205s     0.0003s    0.0038s
  Gen  1        14 colls,     0 par    0.662s   0.662s     0.0473s    0.1180s

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

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

  INIT    time    0.001s  (  0.000s elapsed)
  MUT     time    4.659s  (  5.183s elapsed)
  GC      time    1.865s  (  1.867s elapsed)
  EXIT    time    0.001s  (  0.010s elapsed)
  Total   time    6.526s  (  7.060s elapsed)

  Alloc rate    3,428,220,794 bytes per MUT second

  Productivity  71.4% of total user, 73.4% of total elapsed

Documentation created:
/home/matt/Projects/persistent/dist-newstyle/build/x86_64-linux/ghc-9.4.3/persistent-2.14.4.3/doc/html/persistent/index.html

Log printed to dist-newstyle/haddock-logs/13:04_2022-04-21_haddock-builder.txt
Used haddock: /home/matt/.cabal/bin/haddock-builder

Final Performance Comparison:

Comparing these figures, we have:

Haddock Head xhtml Builder Absolute Difference Relative Change
HTML allocations 1134 MB 1141 MB +7 MB 0.6% worse
HTML time: 380 ms 198 ms -182 ms 47.9% improvement
Total Memory: 554 MB 466 MB -88 MB 15.9% improvement
Total Allocated: 16.0 GB 16.0 GB 0 No change
Max residency: 238 MB 195 MB -43 MB 18.1% improvement
Total Time: 10.88 s 6.526s s -4.354 s 40% improvement

Pretty pleased with these results.

parsonsmatt commented 1 year ago

I can't reproduce the performance, and when checking lately, I can't get this patch to be faster, at all. Going to close this out until I can figure out WTF is going on.