[GHC] #12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O)

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level
lists and -O)
-------------------------------------+-------------------------------------
Reporter: | Owner:
mikhail.vorozhtsov |
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: Compile-time
Unknown/Multiple | performance bug
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
After upgrading to GHC 8.0.1 I've noticed that compilation time of one of
my libraries got unacceptably long. Please find the attached test case.
Here are some numbers from my machine:
{{{
$ time ~/Prefixes/ghc-7.10.3/bin/ghc -O -c -Rghc-timing TypeList.hs
Regression.hs
<

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: mikhail.vorozhtsov | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mikhail.vorozhtsov): * Attachment "TypeList.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: mikhail.vorozhtsov | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mikhail.vorozhtsov): * Attachment "Regression.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: mikhail.vorozhtsov | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): Thanks for the great test case! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level
lists and -O)
-------------------------------------+-------------------------------------
Reporter: | Owner:
mikhail.vorozhtsov |
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Compile-time | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by mikhail.vorozhtsov):
The results of putting `NOINLINE` on `elemWitness`:
{{{
$ time ~/Prefixes/ghc-7.10.3/bin/ghc -O -c -Rghc-timing TypeList.hs
Regression.hs
<

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: mikhail.vorozhtsov | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Inlining Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * keywords: => Inlining -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: mikhail.vorozhtsov | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Inlining Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): The interface file produced by both versions is absolutely huge (17mb). A very large number of coercions are generated by the instance declarations in Regression.hs. Interestingly, one way to improve the performance is marking `elemWitness` as inlinable.. This stops the unfoldings being optimised but it doesn't bring performance to the same level as omitting unfoldings completely. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: mikhail.vorozhtsov | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Inlining Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Several points here * We don't yet know why 8.0 is worse than 7.10. That would e helpful. * The coercions record a proof of all the list manipulations involved. It's not surprising that they can get big. What is surprising is why they are bigger with 8.0 * GHC includes a "coercion optimiser" `OptCoercion.hs`, which tries to shrink a big coercion to a smaller but equivalent coercion. It's possible that 8.0 is somehow missing a crucial optimisation that fires in 7.10. * We also have a plan, recorded in Trac #8095, to discard coercions altogether. But neither Richard or I have found time to execute on that plan. See also #11598 Bottom line: more insight into what is going on would be really helpful. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: mikhail.vorozhtsov | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Inlining Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mikhail.vorozhtsov): Here are some numbers from `-v4` logs: {{{ $ grep -E '(=====|^Result|coercions)' out-7_10.log | grep -v 'RHS size' | head -40 ==================== Parser ==================== ==================== Source Statistics ==================== ==================== Occurrence analysis ==================== ==================== Desugar (after optimization) ==================== Result size of Desugar (after optimization) = {terms: 2,144, types: 128,368, coercions: 415,496} ==================== Occurrence analysis ==================== Result size of Simplifier iteration=1 = {terms: 3,200, types: 173,424, coercions: 415,528} ==================== Occurrence analysis ==================== Result size of Simplifier = {terms: 3,200, types: 173,424, coercions: 415,528} ==================== Specialise ==================== Result size of Specialise = {terms: 12,416, types: 658,320, coercions: 455,704} ==================== FloatOut stats: ==================== Result size of Float out(FOS {Lam = Just 0, = {terms: 13,472, types: 739,808, coercions: 455,704} ==================== Occurrence analysis ==================== Result size of Simplifier iteration=1 = {terms: 30,336, types: 1,848,096, coercions: 6,417,128} ==================== Occurrence analysis ==================== Result size of Simplifier = {terms: 30,336, types: 1,848,096, coercions: 6,417,128} ==================== Occurrence analysis ==================== Result size of Simplifier = {terms: 30,336, types: 1,848,096, coercions: 6,417,128} ==================== Occurrence analysis ==================== Result size of Simplifier = {terms: 30,336, types: 1,848,096, coercions: 6,417,128} Result size of Float inwards = {terms: 30,336, types: 1,848,096, coercions: 6,417,128} ==================== Called arity analysis ==================== Result size of Called arity analysis = {terms: 30,336, types: 1,848,096, coercions: 6,417,128} ==================== Occurrence analysis ==================== }}} for 7.10.3 versus {{{ $ grep -E '(=====|^Result|coercions)' out-8_0.log | grep -v 'RHS size' | head -40 ==================== Parser ==================== ==================== Source Statistics ==================== ==================== Occurrence analysis ==================== ==================== Desugar (after optimization) ==================== Result size of Desugar (after optimization) = {terms: 3,835, types: 147,262, coercions: 549,848} ==================== Occurrence analysis ==================== Result size of Simplifier iteration=1 = {terms: 4,897, types: 161,681, coercions: 549,849} ==================== Occurrence analysis ==================== Result size of Simplifier = {terms: 4,897, types: 161,681, coercions: 549,849} ==================== Specialise ==================== Result size of Specialise = {terms: 17,793, types: 899,977, coercions: 3,094,577} ==================== FloatOut stats: ==================== Result size of Float out(FOS {Lam = Just 0, = {terms: 20,769, types: 1,109,785, coercions: 3,094,577} ==================== Occurrence analysis ==================== Result size of Simplifier iteration=1 = {terms: 16,553, types: 871,953, coercions: 2,232,281} ==================== Occurrence analysis ==================== Result size of Simplifier = {terms: 16,429, types: 864,761, coercions: 2,184,448} ==================== Occurrence analysis ==================== Result size of Simplifier = {terms: 16,429, types: 864,761, coercions: 2,184,448} ==================== Occurrence analysis ==================== Result size of Simplifier iteration=1 = {terms: 87,357, types: 4,366,893, coercions: 10,008,352} ==================== Occurrence analysis ==================== Result size of Simplifier = {terms: 87,357, types: 4,366,893, coercions: 10,008,352} Result size of Float inwards = {terms: 87,357, types: 4,366,893, coercions: 10,008,352} ==================== Called arity analysis ==================== Result size of Called arity analysis = {terms: 87,357, types: 4,366,893, coercions: 10,008,352} ==================== Occurrence analysis ==================== }}} for 8.0.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: mikhail.vorozhtsov | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Inlining Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): This, to me, does not look like a cut-and-dried type-level issue. Note that the number of ''terms'' is much greater in 8.0. And the ratio of coercions to terms is ''lower'' in 8.0 than 7.10. It looks like the occurrence analysis in 8.0 is to blame for the blowup in terms... whereas that same pass in 7.10 caused more of a blowup in coercions. Weird. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level
lists and -O)
-------------------------------------+-------------------------------------
Reporter: | Owner: (none)
mikhail.vorozhtsov |
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords: Inlining
Operating System: Unknown/Multiple | Architecture:
Type of failure: Compile-time | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by RyanGlScott):
A sizable chunk of the regression came from commit
6746549772c5cc0ac66c0fce562f297f4d4b80a2 (Add kind equalities to GHC.)
{{{
Commit 6e56ac58a6905197412d58e32792a04a63b94d7e (Fix infix record field
fixity (#11167 and #11173).)
-----
$ time ghc4/inplace/bin/ghc-stage2 -fforce-recomp -O -c -Rghc-timing
TypeList.hs Regression.hs
<

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level
lists and -O)
-------------------------------------+-------------------------------------
Reporter: | Owner: (none)
mikhail.vorozhtsov |
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords: Inlining
Operating System: Unknown/Multiple | Architecture:
Type of failure: Compile-time | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by RyanGlScott):
Found it. The other culprit is commit
1722fa106e10e63160bb2322e2ccb830fd5b9ab3 (Fix #11230.):
{{{
Commit ae86eb9f72fa7220fe47ac54d6d21395691c1308 (Fix tcTyClTyVars to
handle SigTvs)
-----
$ time ghc4/inplace/bin/ghc-stage2 -fforce-recomp -O -c -Rghc-timing
TypeList.hs Regression.hs
<

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: (none) mikhail.vorozhtsov | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Inlining Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by nh2): * cc: nh2 (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level
lists and -O)
-------------------------------------+-------------------------------------
Reporter: | Owner: (none)
mikhail.vorozhtsov |
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords: Inlining
Operating System: Unknown/Multiple | Architecture:
Type of failure: Compile-time | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: (none) mikhail.vorozhtsov | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Inlining Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): See [https://mail.haskell.org/pipermail/ghc-devs/2017-May/014277.html this ghc-devs thread], and [https://mail.haskell.org/pipermail/ghc- devs/2017-June/014278.html this one]. There seem to be several issues: * Why does the small change identified by Ryan have such a huge effect? We need insight. * The change that Richard made to `CoreOpt.simple_opt_expr` actually fixed an outright bug. But it's ''still'' wrong now. See Trac #13798. * The fuss that is caused by this `map/coerce` rule is out of all proportion to its importance. We should think of a better way. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: (none) mikhail.vorozhtsov | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Inlining Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Incidentally, HEAD is much much better: {{{ 7.10 19.2G allocated by GHC 50 seconds HEAD 7.1G allocated by GHC 30 seconds }}} I gave up waiting for 8.0. So apparently the original problem has gone away, although I'd quite like to know how! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level
lists and -O)
-------------------------------------+-------------------------------------
Reporter: | Owner: (none)
mikhail.vorozhtsov |
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords: Inlining
Operating System: Unknown/Multiple | Architecture:
Type of failure: Compile-time | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by RyanGlScott):
Well hot dang. It turns out that commit
2b74bd9d8b4c6b20f3e8d9ada12e7db645cc3c19 (Stop the specialiser generating
loopy code) is once again responsible for fixing the problem!
{{{
Commit 92a4f908f2599150bec0530d688997f03780646e (Spelling typos)
<

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: (none) mikhail.vorozhtsov | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Inlining Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nh2): I've backported the above mentioned fix to GHC 8.0.2 and created bindist for Linux: https://github.com/nh2/ghc/releases/tag/ghc-8.0.2-bugfix-12545-backport-2017... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: (none) mikhail.vorozhtsov | Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Inlining Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3632 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D3632 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level
lists and -O)
-------------------------------------+-------------------------------------
Reporter: | Owner: (none)
mikhail.vorozhtsov |
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords: Inlining
Operating System: Unknown/Multiple | Architecture:
Type of failure: Compile-time | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D3632
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#12545: Compilation time/space regression in GHC 8.0/8.1 (search in type-level lists and -O) -------------------------------------+------------------------------------- Reporter: | Owner: (none) mikhail.vorozhtsov | Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Inlining Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Compile-time | Test Case: performance bug | perf/compiler/T12545 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3632 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * testcase: => perf/compiler/T12545 * resolution: => fixed * milestone: => 8.2.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12545#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC