[GHC] #8763: forM_ [1..N] does not get fused (10 times slower than go function)
GHC
ghc-devs at haskell.org
Mon Apr 28 15:17:08 UTC 2014
#8763: forM_ [1..N] does not get fused (10 times slower than go function)
--------------------------------------------+------------------------------
Reporter: nh2 | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.6.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime performance bug | Unknown/Multiple
Test Case: | Difficulty: Unknown
Blocking: | Blocked By:
| Related Tickets:
--------------------------------------------+------------------------------
Comment (by nh2):
@simonpj: Summary:
1) I reported that my manually written loop is much faster than `forM_
[1..n]` in some cases, suggesting that in some cases optimizing the list
away doesn't work well.
2) nomeata said some technical things that are a bit beyond me.
3) I submit two benchmarks in the gist at
https://gist.github.com/nh2/11333427, a "matmult" benchmark where there
is a big difference between `forM_` and the hand-written `loop`, and a
"simple" benchmark where they are equally fast.
4) Daniel suspects the slow case comes from using the same syntactical
list twice, and that in this case GHC floats it out to share it, which
breaks eliminating it. He suggests we might special-case `enumFromTo` when
used with `forM_` to prevent it.
5) I give a counter example for his suspicion, by changing my "simple"
benchmark, where using the same list twice gives the same good performance
as using it once.
I get the same behaviour for 7.6 and 7.8.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8763#comment:14>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list