Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,401
    • Issues 5,401
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 590
    • Merge requests 590
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #20134
Closed
Open
Issue created Jul 20, 2021 by dunrix@dunrix

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.

TuplesTH.hs

Tuples.hs

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.

Edited Jul 20, 2021 by dunrix
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking