[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

#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

There is nothing that tests these functions in isolation although it's
#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]: 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
participants (1)
-
GHC