[Haskell-cafe] uvector package appendU: memory leak?

Manlio Perillo manlio_perillo at libero.it
Sun Mar 29 17:17:50 EDT 2009

Claus Reinke ha scritto:
>>>     IntMap (UArr (Word16 :*: Word8))
>>> I was adding elements to the map using something like:
>>>     v = map singletonU (a :*: b)
>>>     insertWith appendU k v m
>>> However doing this eats a *lot* of memory.
> Since 'insertWith' doesn't actually do the 'appendU', the appends
> will also be compressed in time, at point of use, rather than spread
> out in time, over construction. Which might be inconvenient if large
> volumes of data are involved.

Ah, ok; that may explain the problem, but I'm still not sure.

With this program:

Memory usage seems ok.
955 MB, against 622 MB when ratings are grouped by movies
(  using [(MovieID, UArr (Word32 :*: Word8))]  )

The version using `insertWith appendU` is here:

I still can not explain so much difference in memory usage.

>>> So the question is: why appending an array of only one element to an  
>>> existing array causes memory problems?
>> It must copy the entire array.
> And doing this repeatedly, with arrays of increasing length, would
> not be a good idea. 

I can't really see other solutions.

> For single-threaded use, one might use fusion
> to avoid the construction/recopying of the intermediate arrays.

Fusion is not possible, in my case, IMHO.
I'm parsing movie ratings, where we have customers ratings for each 
movie in separate files (17770 total movies).

Each file has format

I want to group ratings by customers, instead of grouping them by movies.
Stream fusion is only possible in the latter case (but in this case I 
don't even need an IntMap).

I'm missing something?

 > [...]


More information about the Haskell-Cafe mailing list