[GHC] #9885: ghc-pkg parser eats too much memory

#9885: ghc-pkg parser eats too much memory
-------------------------------------+-------------------------------------
Reporter: gnezdo | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: ghc-pkg | Version: 7.8.3
Keywords: | Operating System: Linux
Architecture: Unknown/Multiple | Type of failure: Runtime
Difficulty: Moderate (less | performance bug
than a day) | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
Parsing of spec files in ghc-pkg scales very poorly. The following script
demonstrates memory consumption growth as a function of the number of
tokens in ld-options (16K leads to ~6G)
#!/bin/bash
# Demonstrates memory consumption behavior of ghc-pkg as a function of
# the number of ld-options arguments.
for i in {10..14}; do
size=$((1 << $i))
echo $size
rm -fr a.packages
/usr/bin/ghc-pkg init a.packages
cat > a.spec <

#9885: ghc-pkg parser eats too much memory
-------------------------------------+-------------------------------------
Reporter: gnezdo | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: ghc-pkg | Version: 7.8.3
Resolution: | Keywords:
Operating System: Linux | Architecture: Unknown/Multiple
Type of failure: Runtime | Difficulty: Moderate (less
performance bug | than a day)
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by gnezdo):
I did some profiling. To save somebody a bit of digging, reproducing the
build/profile/plot script here (would love to hear how to do this more
optimally):
{{{
#!/bin/bash
# Demonstrates memory consumption behavior of ghc-pkg as a function of
# the number of ld-options arguments.
set -eu
(cd ~/ghc-copy/Cabal/Cabal && cabal install --enable-library-profiling
--enable-executable-profiling --force-reinstalls --ghc-option=-rtsopts
--ghc-option=-prof --ghc-option=-fprof-auto)
(cd ~/ghc-copy/ghc/libraries/bin-package-db && cabal install --enable-
library-profiling --enable-executable-profiling --force-reinstalls --ghc-
option=-rtsopts --ghc-option=-prof --ghc-option=-fprof-auto)
(cd ~/ghc-copy/ghc/utils/ghc-pkg && cabal install --enable-library-
profiling --enable-executable-profiling --force-reinstalls --ghc-
option=-rtsopts --ghc-option=-prof --ghc-option=-fprof-auto --ghc-
option=-DBOOTSTRAPPING)
ghcpkg=~/.cabal/bin/ghc-pkg
for i in {13..13}; do
size=$((1 << $i))
echo $size
rm -fr a.packages
$ghcpkg init a.packages
cat > a.spec <

#9885: ghc-pkg parser eats too much memory -------------------------------------+------------------------------------- Reporter: gnezdo | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: ghc-pkg | Version: 7.8.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: Runtime | Difficulty: Moderate (less performance bug | than a day) Test Case: | Blocked By: Blocking: | Related Tickets: Differential Revisions: | -------------------------------------+------------------------------------- Comment (by gnezdo): The most expensive place seems to be this (quoted from .hp file, lightly munged): {{{ (953)>>=.\.\.(...) >>=.\.\ >>=.\ >>= many1 many sepBy1 sepBy parseSepList parseOptCommaList listField installedFieldDescrs accumFields.setField accumFields parseFieldsFlat.\ parseFieldsFlat parseInstalledPackageInfo parsePackageInfo registerPackage runit main 794023536 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9885#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9885: ghc-pkg parser eats too much memory -------------------------------------+------------------------------------- Reporter: gnezdo | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: ghc-pkg | Version: 7.8.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: Runtime | Difficulty: Moderate (less performance bug | than a day) Test Case: | Blocked By: Blocking: | Related Tickets: Differential Revisions: | -------------------------------------+------------------------------------- Comment (by gnezdo): Filed as https://github.com/haskell/cabal/issues/2276 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9885#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9885: ghc-pkg parser eats too much memory -------------------------------------+------------------------------------- Reporter: gnezdo | Owner: Type: bug | Status: new Priority: low | Milestone: Component: ghc-pkg | Version: 7.8.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: Runtime | Difficulty: Moderate (less performance bug | than a day) Test Case: | Blocked By: Blocking: | Related Tickets: Differential Revisions: | -------------------------------------+------------------------------------- Changes (by gnezdo): * priority: normal => low Comment: My workaround for this was to split the long comma separated list of ld- options into multiple ld-options with one item per line. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9885#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9885: ghc-pkg parser eats too much memory
-------------------------------------+-------------------------------------
Reporter: gnezdo | Owner: (none)
Type: bug | Status: new
Priority: low | Milestone:
Component: ghc-pkg | Version: 7.8.3
Resolution: | Keywords:
Operating System: Linux | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#9885: ghc-pkg parser eats too much memory -------------------------------------+------------------------------------- Reporter: gnezdo | Owner: (none) Type: bug | Status: closed Priority: low | Milestone: 8.4.1 Component: ghc-pkg | Version: 7.8.3 Resolution: fixed | Keywords: Operating System: Linux | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed * milestone: => 8.4.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9885#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC