[GHC] #8638: Optimize by demoting "denormalized" Integers (i.e. J# -> S#)

GHC ghc-devs at haskell.org
Mon Dec 30 19:26:22 UTC 2013


#8638: Optimize by demoting "denormalized" Integers (i.e. J# -> S#)
--------------------------------------------+------------------------------
        Reporter:  hvr                      |            Owner:  hvr
            Type:  feature request          |           Status:  infoneeded
        Priority:  normal                   |        Milestone:  7.8.1
       Component:  libraries (other)        |          Version:  7.7
      Resolution:                           |         Keywords:  integer-
Operating System:  Unknown/Multiple         |  gmp
 Type of failure:  Runtime performance bug  |     Architecture:
       Test Case:                           |  Unknown/Multiple
        Blocking:                           |       Difficulty:  Unknown
                                            |       Blocked By:
                                            |  Related Tickets:
--------------------------------------------+------------------------------

Comment (by hvr):

 Replying to [comment:3 simonpj]:
 > I'd first like to know why `mandel` started allocating nearly 50% more
 store.  (I use `-ticky` for answering this kind of question.)  Maybe
 investigating that will show how the patch can be improved further.

 I'm not sure yet why `mandel` allocates more as I couldn't see find any
 significant use of `Integer`s in the implementation. After some profiling
 I found out that swapping out the implementation of `magnitude` inside
 `Mandel.diverge` with a more naive one had a ''huge'' effect on the
 allocation.

 Now the report reads:

 {{{
 --------------------------------------------------------------------------------
         Program           Size    Allocs   Runtime   Elapsed  TotalMem
 --------------------------------------------------------------------------------
 ...
        maillist          +0.0%     +0.0%      0.04      0.04     +2.2%
          mandel          -0.2%    -45.4%      0.02      0.02     +0.0%
         mandel2          +0.0%     +0.0%      0.00      0.00     +0.0%
 ...
 --------------------------------------------------------------------------------
             Min          -0.2%    -45.4%    -32.3%    -32.3%    -20.0%
             Max          +0.1%     +7.2%     +1.6%     +1.6%    +23.1%
  Geometric Mean          +0.1%     -1.3%     -1.7%     -1.8%     +0.0%
 }}}

 The modification I made was simply

 {{{
 #!diff
 diff --git a/spectral/mandel/Mandel.lhs b/spectral/mandel/Mandel.lhs
 index 3f460ce..cc601f5 100644
 --- a/spectral/mandel/Mandel.lhs
 +++ b/spectral/mandel/Mandel.lhs
 @@ -109,6 +109,8 @@ is the prelude function that calculates the euclidean
 norm

  diverge::Complex Double -> Double -> Bool
  diverge cmplx radius =  magnitude cmplx > radius
 +  where
 +    magnitude (x :+ y) = sqrt (x*x + y*y)
  \end{code}

 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8638#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list