[GHC] #10034: Regression in mapM_ performance

#10034: Regression in mapM_ performance -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: ekmett Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Core | Version: 7.10.1-rc2 Libraries | Operating System: Unknown/Multiple Keywords: | Type of failure: Runtime Architecture: | performance bug Unknown/Multiple | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: Phab:D632 | -------------------------------------+------------------------------------- The current `mapM_` is sometimes worse than the version in 7.8.3. This can be fixed easily by eta-expansion, matching `mapM`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10034 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10034: Regression in mapM_ performance -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: ekmett Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Core Libraries | Version: 7.10.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D632 -------------------------------------+------------------------------------- Comment (by simonpj): Can you offer a reproducible test case, and timing or allocation data? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10034#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10034: Regression in mapM_ performance -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: ekmett Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Core Libraries | Version: 7.10.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D632 -------------------------------------+------------------------------------- Comment (by dfeuer): Replying to [comment:1 simonpj]:
Can you offer a reproducible test case, and timing or allocation data?
I had one, and then I lost it. I wish I could give you one as a test case and for future analysis. It was something very simple, and the `mapM_` of 4.7 was consistently the same as the version in the linked differential, and both allocated less than the version currently in head. I believe it had to be an arity issue. Call arity wasn't catching it for some reason, so it needed input from the other arity analysis that it wasn't getting. Consider the current definition: {{{#!hs mapM_ f = foldr ((>>) . f) (return ()) }}} Taking apart the argument to `foldr` above gives {{{#!hs mapM_ f = foldr (\m -> (>>) (f m)) (return ()) }}} Now fuse this with `build g`: {{{#!hs mapM_ f (build g) = g (\m -> (>>) (f m)) (return ()) }}} Without knowing what the monad is, `mapM_` doesn't know that `(>>)` has arity 2, and relies on Call Arity analysis of `g`, which I imagine wasn't working in whatever example I was dealing with. What I propose below forces the arity up to 2, and is also significantly easier to read. {{{#!hs {-# INLINE mapM_ #-} mapM_ f = foldr (\m n -> f m >> n) (return ()) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10034#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10034: Regression in mapM_ performance -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: ekmett Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Core Libraries | Version: 7.10.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D632 -------------------------------------+------------------------------------- Comment (by simonpj): I still don't follow from comment:2 where the performance loss you describe is coming from, nor why inlining `mapM` will help. If you do have a clear idea, can you ''construct'' an example? Switch off Call Arity if you like. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10034#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10034: Regression in mapM_ performance
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner: ekmett
Type: bug | Status: new
Priority: normal | Milestone: 7.10.1
Component: Core Libraries | Version: 7.10.1-rc2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions: Phab:D632
-------------------------------------+-------------------------------------
Comment (by Austin Seipp

#10034: Regression in mapM_ performance -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: ekmett Type: bug | Status: new Priority: highest | Milestone: 7.10.1 Component: Core Libraries | Version: 7.10.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D632 -------------------------------------+------------------------------------- Changes (by simonpj): * priority: normal => highest Comment: I'm very unhappy with applying this patch without any comments, and without any understanding of what is going on. Now `mapM_` has an INLINE pragma that may or may not be necessary, and an eta-expanded argument, and no one understands which of the two is important, if either. Maybe there is a simplifier bug underlying this, which is simply being covered up. Please please can we have a reproducible test case that shows the regression. Ideally one that just showed it, but if it's necessary to switch Call Arity off (which you hypothesise is making the test case harder to create) then do that. But please let's NOT just cover up the problem. I'm quite inclined to revert the patch, just to serve as a forcing function to try to elicit this information. For now I'll just increase the priority to try to make sure we notice it. I know it's a nuisance, but this is an example of what people mean by incurring technical debt. Thanks! Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10034#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10034: Regression in mapM_ performance
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner: ekmett
Type: bug | Status: new
Priority: highest | Milestone: 7.10.1
Component: Core Libraries | Version: 7.10.1-rc2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions: Phab:D632
-------------------------------------+-------------------------------------
Comment (by Austin Seipp

#10034: Regression in mapM_ performance -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: ekmett Type: bug | Status: new Priority: normal | Milestone: 7.12.1 Component: Core Libraries | Version: 7.10.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D632 -------------------------------------+------------------------------------- Changes (by thoughtpolice): * priority: highest => normal * milestone: 7.10.1 => 7.12.1 Comment: Moving out to 7.12 for now pending a better test case/example of where this is going wrong. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10034#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10034: Regression in mapM_ performance -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: bgamari Type: bug | Status: new Priority: normal | Milestone: 7.12.1 Component: Core Libraries | Version: 7.10.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D632 -------------------------------------+------------------------------------- Changes (by bgamari): * owner: ekmett => bgamari -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10034#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10034: Regression in mapM_ performance -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: bgamari Type: bug | Status: new Priority: normal | Milestone: 7.12.1 Component: Core Libraries | Version: 7.10.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D632 -------------------------------------+------------------------------------- Comment (by bgamari): David, I don't suppose you have stumbled upon an example of this in the months, have you? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10034#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10034: Regression in mapM_ performance -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: bgamari Type: bug | Status: closed Priority: normal | Milestone: 8.0.1 Component: Core Libraries | Version: 7.10.1-rc2 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D632 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: ekmett (added) * status: new => closed * resolution: => invalid Comment: Closing as we don't have an example demonstrating the issue. David, feel free to reopen if you do come upon a testcase. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10034#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC