[GHC] #3606: The Ord instance for unboxed arrays is very inefficient

GHC trac at galois.com
Thu Oct 22 16:48:52 EDT 2009


#3606: The Ord instance for unboxed arrays is very inefficient
-----------------------------+----------------------------------------------
Reporter:  blarsen           |          Owner:                   
    Type:  bug               |         Status:  new              
Priority:  normal            |      Component:  libraries (other)
 Version:  6.10.4            |       Severity:  normal           
Keywords:                    |       Testcase:                   
      Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple 
-----------------------------+----------------------------------------------
 The Ord instance for unboxed arrays defined in Data.Array.Base results in
 code that makes lots of heap allocations and is very slow.

 For the record, the Ord instance is defined as so in Data.Array.Base:


 {{{
 instance (Ix ix, Ord e, IArray UArray e) => Ord (UArray ix e) where
     compare = cmpUArray

 {-# INLINE cmpUArray #-}
 cmpUArray :: (IArray UArray e, Ix i, Ord e) => UArray i e -> UArray i e ->
 Ordering
 cmpUArray arr1 arr2 = compare (assocs arr1) (assocs arr2)
 }}}

 The 'assocs' calls don't appear to be deforested away, and hence, when
 using the Ord functions on unboxed arrays, the performance is bad to the
 point of making them unusable.

 It seems reasonable to me that 'compare' for unboxed arrays could be
 implemented strictly, in a tight loop, without any heap allocations at
 all.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3606>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list