<div dir="ltr"><div>Hello all! I'm using Alex/Happy to generate a parser for PHP. This is my first go at using a parser generator
instead of parser combinators and it's been going pretty smoothly so
far, but I've hit a snag.</div><div><br></div><div>Compiling the
happy-generated parser is excruciatingly slow -- 20+ minutes with -O0 --
which messes up the typically very fast feedback loop haskell+ghci
allows. Running the code is great; my quickcheck test suite is very
fast. But compiling and loading into ghci are so slow that iterating on
the project further is not practical until I can figure out how to speed
it up.<br></div><div><br></div><div>Are there any folklore techniques for dealing with this problem, or any resources about how to profile/debug slow compilation?<br></div><div><br></div><div>I'm on macos using Stack with lts-13.21, which includes happy-1.19.10.<br></div><div><br></div><div>I tried the ideas in this known issue: <a href="https://github.com/simonmar/happy/issues/109" target="_blank">https://github.com/simonmar/happy/issues/109</a>. I also tried downgrading to lts-6.35 (the most recent with GHC 7.*), all with similar results.<br></div><div><br></div><div>I
imagine some of this slowdown is inevitable because of the grammar's
size; it has ~275 nonterminals and the generated `Parser.hs` module is
3.8MB. Usually for a problem like this I'd break the module up into
smaller pieces that won't change as often, but in this case it's an
opaque monolith generated by happy. I also see that the generated code doesn't have type signatures on all top level functions.<br></div><div><br></div><div>Here's the relevant output from GHC with -v2 enabled:<br></div><div><br></div><div>```</div><div>*** Parser [PHP.Parse.Parser]:<br>!!! Parser [PHP.Parse.Parser]: finished in 1980.24 milliseconds, allocated 3155.733 megabytes<br>*** Renamer/typechecker [PHP.Parse.Parser]:<br>!!! Renamer/typechecker [PHP.Parse.Parser]: finished in 243923.86 milliseconds, allocated 178189.005 megabytes<br>*** Desugar [PHP.Parse.Parser]:<br>Result size of Desugar (before optimization)<br> = {terms: 1,346,664,<br> types: 672,082,252,<br> coercions: 789,<br> joins: 0/9,651}<br>Result size of Desugar (after optimization)<br> = {terms: 834,353,<br> types: 285,053,589,<br> coercions: 246,053,<br> joins: 235/735}<br>!!! Desugar [PHP.Parse.Parser]: finished in 103983.68 milliseconds, allocated 17597.213 megabytes<br>*** Simplifier [PHP.Parse.Parser]:<br>Result size of Simplifier iteration=1<br> = {terms: 1,059,012,<br> types: 69,942,882,<br> coercions: 1,934,739,<br> joins: 235/1,935}<br>Result size of Simplifier iteration=2<br> = {terms: 815,760,<br> types: 64,805,160,<br> coercions: 1,368,873,<br> joins: 233/1,929}<br>Result size of Simplifier<br> = {terms: 776,400,<br> types: 64,474,214,<br> coercions: 1,297,320,<br> joins: 233/1,929}<br>!!! Simplifier [PHP.Parse.Parser]: finished in 197842.50 milliseconds, allocated 116983.797 megabytes<br>*** CoreTidy [PHP.Parse.Parser]:<br>Result size of Tidy Core<br> = {terms: 776,400,<br> types: 64,474,214,<br> coercions: 1,297,320,<br> joins: 233/1,929}<br>!!! CoreTidy [PHP.Parse.Parser]: finished in 97776.92 milliseconds, allocated 11254.968 megabytes<br>*** CorePrep [PHP.Parse.Parser]:<br>Result size of CorePrep<br> = {terms: 795,714,<br> types: 66,237,082,<br> coercions: 1,297,320,<br> joins: 233/4,234}<br>!!! CorePrep [PHP.Parse.Parser]: finished in 7911.78 milliseconds, allocated 2564.067 megabytes<br>*** Stg2Stg:<br>*** CodeGen [PHP.Parse.Parser]:<br>!!! CodeGen [PHP.Parse.Parser]: finished in 7048.73 milliseconds, allocated 6407.563 megabytes<br>*** Assembler:<br>*** CorePrep [PHP.Parse.Parser]:<br>Result size of CorePrep<br> = {terms: 795,714,<br> types: 66,237,082,<br> coercions: 1,297,320,<br> joins: 233/4,234}<br>!!! CorePrep [PHP.Parse.Parser]: finished in 3069.67 milliseconds, allocated 2564.018 megabytes<br>*** Stg2Stg:<br>*** CodeGen [PHP.Parse.Parser]:<br>!!! CodeGen [PHP.Parse.Parser]: finished in 5970.62 milliseconds, allocated 6634.422 megabytes<br>*** Assembler:<br>*** Deleting temp files:<br>Warning: deleting non-existent /var/folders/td/sxyy9wl919740vddr49g8nth0000gn/T/ghc1272_0/ghc_70.s<br>Warning: deleting non-existent /var/folders/td/sxyy9wl919740vddr49g8nth0000gn/T/ghc1272_0/ghc_72.c<br>Warning: deleting non-existent /var/folders/td/sxyy9wl919740vddr49g8nth0000gn/T/ghc1272_0/ghc_74.c<br></div><div>```</div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Nathan Bloomfield<br></div>Systems Analyst, Team Neutron<br></div><div>Automattic, Inc.<br></div></div></div></div></div>