Excessive memory allocation at Template Haskell compilation
Summary
Uncommon huge memory footprint at compilation of Template Haskell code.
Steps to reproduce
See bellow for an example with link to related source files.
Expected behavior
Proportionate memory requirements, like at compilation of comparable non-TH sources.
Environment
- GHC version used: 9.0.1
Optional:
- Operating System: Linux
- System Architecture: x86_64
$ /usr/bin/time ghc -O Tuples.hs
[1 of 2] Compiling TuplesTH ( TuplesTH.hs, TuplesTH.o, TuplesTH.dyn_o )
[2 of 2] Compiling Main ( Tuples.hs, Tuples.o, Tuples.dyn_o )
Linking Tuples ...
22.06user 1.08system 0:23.64elapsed 97%CPU (0avgtext+0avgdata 1798144maxresident)k
1440inputs+66440outputs (43major+486031minor)pagefaults 0swaps
Whopping 1,800 MB of RSS memory at generating 62 typeclasses and 1953 instances.
Middle-sized Servant project, for example, requires at compilation about 450MB at peak only.
Edit
As @mpickering did suggested, I've attempted to compile above example without Template Haskell, but with tuple classes & accessor instances generated from former output of -ddump-splices
. In the end, I did got equivalent results.
So the assumption it is related to TH or template-haskell
package and/or its dependencies is now unconfimed.
It now boils down to, how effective is GHC at compilation of tuples of various sizes. If for 62 typeclasses and related tuple accessor functions is adequate demand 1.8 GB of resident memory.