[GHC] #14037: Fix fusion for GHC's utility functions
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 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: -------------------------------------+------------------------------------- In a patchset I'm working on, I encountered a smallish "bytes allocated" regression in `perf/compiler/T5631`. After some sleuthing, I discovered that the regression is caused by using a `zipWith3M` where previously there was a `zipWithM`. Interestingly, it was not the zipped function that caused the problem, but the `zipWith3M` itself. Further sleuthing found that `zipWithM` is inlined into a combination of `sequenceA` and `zipWith`, both of which have been taught to work nicely with fusion. I thought of doing the same to GHC's `zipWith3M`, but I discovered that `base`'s `zipWith3` has no rules or inlining pragmas, suggesting that it does not fuse. I was quite surprised to find this, thinking that all functions as basic as `zipWith3` in `base` would play nicely with fusion. (Perhaps it does fuse -- I didn't actually check.) I then checked out GHC's `MonadUtils`, which defines a bunch of functions, some of which must be hammered on, and only one of which has any kind of performance- enhancing pragma. (The one is `zipWithAndUnzipM`, whose `INLINABLE` pragma was added only after much pain suffered by your dear author.) So: this ticket is a request to sweep through `MonadUtils` and `Util` and perhaps `ListSetOps`, looking for performance enhancements via fusion, tighter definitions, and such. Also, get `zipWith3` (and the other `zipWith`s) to fuse in `base`. I figure this is all some fairly low-hanging fruit for performance improvements in GHC. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 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 Richard Eisenberg <rae@…>): In [changeset:"fb752133f45f01b27240d7cc6bce2063a015e51b/ghc" fb75213/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="fb752133f45f01b27240d7cc6bce2063a015e51b" Track visibility in TypeEqOrigin A type equality error can arise from a mismatch between *invisible* arguments just as easily as from visible arguments. But we should really prefer printing out errors from visible arguments over invisible ones. Suppose we have a mismatch between `Proxy Int` and `Proxy Maybe`. Would you rather get an error between `Int` and `Maybe`? Or between `*` and `* -> *`? I thought so, too. There is a fair amount of plumbing with this one, but I think it's worth it. This commit introduces a performance regression in test perf/compiler/T5631. The cause of the regression is not the new visibility stuff, directly: it's due to a change from zipWithM to zipWith3M in TcUnify. To my surprise, zipWithM is nicely optimized (it fuses away), but zipWith3M is not. There are other examples of functions that could be made faster, so I've posted a separate ticket, #14037, to track these improvements. For now, I've accepted the small (6.6%) regression. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: newcomer 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 thomie): * keywords: => newcomer -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: newcomer 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 rockbmb): I'd like to take this issue on, but before I do I'll take a look at the modules in question. Is there a benchmarking suite in GHC that includes the functions mentioned? If not then that would also be part of the issue. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: newcomer 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 rockbmb): * owner: (none) => rockbmb -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: newcomer 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 bgamari): There is nothing that tests these functions in isolation although it's possible improvements would be reflected in the compiler allocations measured by the Nofib suite. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: newcomer 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 rockbmb): Replying to [comment:5 bgamari]:
There is nothing that tests these functions in isolation although it's possible improvements would be reflected in the compiler allocations measured by the Nofib suite.
I've been reading [https://ghc.haskell.org/trac/ghc/wiki/Building/RunningNoFib this] resource on NoFib, very useful. I'll keep what you said in mind. Since the OP also mentions `testsuite/tests/perf/compiler/T5631`, I'm also reading https://ghc.haskell.org/trac/ghc/wiki/Building/RunningTests so I can test the specific case described. I've already added some pragma code to `zipWith3, zipWith3M, zipwith4, zipwith4M`. In the coming days I'll run benchmarks. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): D5240 Wiki Page: | -------------------------------------+------------------------------------- Changes (by rockbmb): * differential: => D5240 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: newcomer 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:D5240 Wiki Page: | -------------------------------------+------------------------------------- Changes (by rockbmb): * differential: D5240 => Phab:D5240 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: newcomer 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 rockbmb): * differential: Phab:D5240 => -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: newcomer 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:5249 Wiki Page: | -------------------------------------+------------------------------------- Changes (by rockbmb): * differential: => Phab:5249 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: newcomer 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:D5249 Wiki Page: | -------------------------------------+------------------------------------- Changes (by potato44): * differential: Phab:5249 => Phab:D5249 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: newcomer 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:D5249 Wiki Page: | -------------------------------------+------------------------------------- Comment (by rockbmb): Replying to [comment:11 potato44]: Thanks, I didn't notice that mistake. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:12> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: newcomer 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:D5249 Wiki Page: | -------------------------------------+------------------------------------- Changes (by osa1): * status: new => patch -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:13> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #15263 | Differential Rev(s): Phab:D5249 Wiki Page: | -------------------------------------+------------------------------------- Changes (by TDecki): * related: => #15263 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:14> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #15263 | Differential Rev(s): Phab:D5249 Wiki Page: | -------------------------------------+------------------------------------- Changes (by rockbmb): * status: patch => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:15> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #15263 | Differential Rev(s): Phab:D5249 Wiki Page: | -------------------------------------+------------------------------------- Comment (by rockbmb): Closed after [this MR](https://gitlab.haskell.org/ghc/ghc/merge_requests/421). -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:16> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14037: Fix fusion for GHC's utility functions -------------------------------------+------------------------------------- Reporter: goldfire | Owner: rockbmb Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #15263 | Differential Rev(s): Phab:D5249 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Marge Bot <ben+marge-bot@…>): In [changeset:"9059343e8d1fc94ac62145688d6fdd70a791eaf1/ghc" 9059343e/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="9059343e8d1fc94ac62145688d6fdd70a791eaf1" base: Allow fusion for zip7 and related Fixes #14037. Metric Decrease: T9872b T9872d Reviewers: bgamari, simonpj, hvr Reviewed By: simonpj Subscribers: AndreasK, simonpj, osa1, dfeuer, rwbarton, carter GHC Trac Issues: #14037 Differential Revision: https://phabricator.haskell.org/D5249 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14037#comment:17> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC