Skip to content

Inline cmpUArray for specialization (#3606)

Sylvain Henry requested to merge wip/hsyl20/3606 into master

Fix for ghc/ghc#3606

Test (I'll add it to GHC's repo):

module Main where

import Data.Array.Base
import Control.Monad

l,r :: Num a => a
l = 57
r = 12345
es = [(i,i) | i <- [0, fromIntegral (r-l-1)]]

uarr_int1, uarr_int2 :: UArray Int Int
uarr_int1 = unsafeArray (l,r) (es ++ [(r-l,0)])
uarr_int2 = unsafeArray (l,r) (es ++ [(r-l,1)])

uarr_word1, uarr_word2 :: UArray Word Int
uarr_word1 = unsafeArray (l,r) (es ++ [(r-l,0)])
uarr_word2 = unsafeArray (l,r) (es ++ [(r-l,1)])

main :: IO ()
main = do
  guard (((compare $! uarr_int1) $! uarr_int2) == LT)
  guard (((compare $! uarr_word1) $! uarr_word2) == LT)    

Before:

❯ ./T3606 +RTS -s
       6,136,776 bytes allocated in the heap
           5,712 bytes copied during GC
          35,984 bytes maximum residency (1 sample(s))
          29,552 bytes maximum slop
               6 MiB total memory in use (0 MiB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0         1 colls,     0 par    0.000s   0.000s     0.0000s    0.0000s
  Gen  1         1 colls,     0 par    0.000s   0.000s     0.0002s    0.0002s

  INIT    time    0.003s  (  0.003s elapsed)
  MUT     time    0.005s  (  0.005s elapsed)
  GC      time    0.000s  (  0.000s elapsed)
  EXIT    time    0.000s  (  0.005s elapsed)
  Total   time    0.008s  (  0.013s elapsed)

  %GC     time       0.0%  (0.0% elapsed)

  Alloc rate    1,241,281,635 bytes per MUT second

  Productivity  60.3% of total user, 39.7% of total elapsed

After:

❯ ./T3606 +RTS -s
         434,248 bytes allocated in the heap
           3,144 bytes copied during GC
          35,984 bytes maximum residency (1 sample(s))
          21,360 bytes maximum slop
               6 MiB total memory in use (0 MiB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0         0 colls,     0 par    0.000s   0.000s     0.0000s    0.0000s
  Gen  1         1 colls,     0 par    0.000s   0.000s     0.0003s    0.0003s

  INIT    time    0.005s  (  0.005s elapsed)
  MUT     time    0.001s  (  0.001s elapsed)
  GC      time    0.000s  (  0.000s elapsed)
  EXIT    time    0.000s  (  0.000s elapsed)
  Total   time    0.006s  (  0.006s elapsed)

  %GC     time       0.0%  (0.0% elapsed)

  Alloc rate    707,761,864 bytes per MUT second

  Productivity  10.5% of total user, 10.6% of total elapsed

Merge request reports