[GHC] #12191: 7% allocation regression in Haddock performance tests

#12191: 7% allocation regression in Haddock performance tests -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: task | 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: -------------------------------------+------------------------------------- One of the commits below is responsible for a rather significant [[https://perf.haskell.org/ghc/#revision/d55a9b4fd5a3ce24b13311962bca66155b17a558|regression]] in the `haddock.Cabal` and `haddock.compiler` testcases, {{{ d55a9b4fd5a3ce24b13311962bca66155b17a558 0497ee504cc9ac5d6babee9b98bf779b3fc50b98 586d55815401c54f4687d053fb033e53865e0bf1 7de776cfe7825fca6a71fe6b3854c3c86bf9ca12 5cee88d766723929f789ffcd2ef24d8b5ef62a16 1dcb32ddba605bced2e0e0ce3f52b58e8ff33f5b 921ebc9f0854d033cbafd43d3b2c5ba679c27b3c e064f501d76c208ddab3c3be551ffe5167d7974f 8104f7c674d7ef2db0c25312f48763202dcef57f 599d912f0b85583e389661d85ed2f198e2621bb0 15fc52819c440f9e9b91ce92fcfda3c264cbe1c1 1f661281a23b6eab83a1144c43e464c0e2d2195a 35c9de7ca053eda472cb446c53bcd2007bfd8394 7afb7adf45216701e4f645676ecc0668f64b424d c28dde37f3f274a2a1207dd4e175ea79769f5ead 15b9bf4ba4ab47e6809bf2b3b36ec16e502aea72 }}} It would be nice to identify which of these is the culprit. The fix in `d55a9b4fd5a3ce24b13311962bca66155b17a558` will need to be applied on top of each of these to allow things to build. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12191 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12191: 7% allocation regression in Haddock performance tests -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: task | 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 nomeata): I’m trying to make perf.haskell.org rerun these commits with d55a9b4fd5a3ce24b13311962bca66155b17a558 cherrypicked, and will report back. This should narrow it down. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12191#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12191: 7% allocation regression in Haddock performance tests -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: task | 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: #10482 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * related: => #10482 Comment: How about we just delete those 3 haddock performance tests? From https://mail.haskell.org/pipermail/ghc-devs/2015-July/009434.html:
Simon Peyton Jones wrote: Could it be creeping up because Haddock is doing more than before? Ie not just because GHC is being bad? Yes, it very much could be. Haddock is a moving target so it's not too weird that the numbers change. I want to say that the perf test should just be removed but it's still useful: if you're GHC hacking and not changing Haddock and numbers go awry then it serves its purpose.
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12191#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12191: 7% allocation regression in Haddock performance tests -------------------------------------+------------------------------------- Reporter: bgamari | Owner: niteria Type: task | 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: #10482 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by nomeata): * owner: => niteria Comment: And we have a winner: The culprit is changeset:0497ee504cc9ac5d6babee9b98bf779b3fc50b98 as can be seen on https://perf.haskell.org/ghc/#revision/0497ee504cc9ac5d6babee9b98bf779b3fc50... So Simon is not only freed of any fault, but yet again had a the right intuition about what regressions are worth investigating. Assigning this to niteria. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12191#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12191: 7% allocation regression in Haddock performance tests -------------------------------------+------------------------------------- Reporter: bgamari | Owner: niteria Type: task | 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: #10482 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by niteria): @nomeata: Thanks for running these. I think I had to disable `haddock` before `./validate` because it was broken and that's how this snuck in. I will take a look this week (but unfortunately not tomorrow). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12191#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12191: 7% allocation regression in Haddock performance tests -------------------------------------+------------------------------------- Reporter: bgamari | Owner: niteria Type: task | 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: #10482 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Thanks so much Joachim. I'm mighty relieved! I'll revert Bartosz's patch for now, to keep Phab happy. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12191#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12191: 7% allocation regression in Haddock performance tests
-------------------------------------+-------------------------------------
Reporter: bgamari | Owner: niteria
Type: task | 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: #10482 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#12191: 7% allocation regression in Haddock performance tests -------------------------------------+------------------------------------- Reporter: bgamari | Owner: niteria Type: task | 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: #10482 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by niteria): This appears to be ordering related. Meaning that when things are ordered differently we do different kind of work and it costs more. When I changed `Ord UnitId` from my original diff to {{{ instance Ord UnitId where nm1 `compare` nm2 = -- do the same work, but return the old ordering if stableUnitIdCmp nm1 nm2 == LT then getKey (getUnique nm1) `compare` getKey (getUnique nm2) -- this was enough to stop GHC from being smart and optimize it out else getUnique nm1 `compare` getUnique nm2 }}} The difference went from `7%` to `0.21%`. I will try to narrow this down to functions that are ordering sensitive and see if I can make them stable. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12191#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12191: 7% allocation regression in Haddock performance tests -------------------------------------+------------------------------------- Reporter: bgamari | Owner: niteria Type: task | 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: #10482 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonmar): @thomie, Note that the Haddock perf test is really a GHC perf test, because most of the work that Haddock does is loading source files and typechecking them using the GHC API. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12191#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12191: 7% allocation regression in Haddock performance tests -------------------------------------+------------------------------------- Reporter: bgamari | Owner: niteria Type: task | 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: #10482 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by niteria): It appears that `checkFamInstConsistency` is sensitive to `Module` ordering. Making it a noop also reduces allocations by `9%`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12191#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12191: 7% allocation regression in Haddock performance tests -------------------------------------+------------------------------------- Reporter: bgamari | Owner: niteria Type: task | 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: #10482 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by niteria): So what's happening in `checkFamInstConsistency` is suboptimal in multiple ways: 1) The algorithm itself is quadratic. It checks every module against every other module. It appears to me that the same thing can be done in a linear way by maintaining a consistent env of family instances so far and fold adding there when possible or reporting an error. 2) `checkFamInstConsistency` in Haddock appears to be called for every module (Haddock is equivalent to `--make`, right?) which is redundant and in principle could be done at the very end once. 3) determining what pairs to compare uses `Set ModulePair`. After my change `Ord ModulePair` is linear. The size of the set is quadratic. Furthermore the `Ord ModulePair` doesn't cache its canonicalization. 4) given these there still appear to be better and worse orders for the `ModulePair`s. I don't really know why. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12191#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12191: 7% allocation regression in Haddock performance tests -------------------------------------+------------------------------------- Reporter: bgamari | Owner: niteria Type: task | 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: #10482 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): When typechecking a particular module M, `checkFamInstConsistency` does indeed need to check that the imported family instances are consistent; and that requires checking any instance for `F` imported from `I1` with all instances of `F` imported from some other module `I2`. (Multiple instances all imported from `I1` have already been checked, when compiling `I1`.) I don't understand Haddock's use-case to know why the algorithm is behaving so badly, but I bet there is some low-hanging fruit. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12191#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12191: 7% allocation regression in Haddock performance tests
-------------------------------------+-------------------------------------
Reporter: bgamari | Owner: niteria
Type: task | 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: #10482 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Bartosz Nitka

#12191: 7% allocation regression in Haddock performance tests
-------------------------------------+-------------------------------------
Reporter: bgamari | Owner: niteria
Type: task | 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: #10482 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Bartosz Nitka

#12191: 7% allocation regression in Haddock performance tests -------------------------------------+------------------------------------- Reporter: bgamari | Owner: niteria Type: task | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #10482 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by niteria): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12191#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC