[Haskell-cafe] uvector package appendU: memory leak?
manlio_perillo at libero.it
Mon Mar 30 12:32:48 EDT 2009
Claus Reinke ha scritto:
>> But Claus was right, appendU is lazy; this seems to be the cause of
>> the problem.
> appendU is strict, insertWith just doesn't force it (follow the source link
> in the haddocks to see why).
Ok, I see.
But, IMHO, this should be clearly documented.
I have updated my test code:
The interesting thing is that using appendU is *faster*.
Memory usage is the same.
>> However now I don't really understand why the two implementations
>> differs in lazyness.
>> Or, to ask a different question, how can I make the version using
>> insertWith strict?
> deja vu:-(
Your are right, sorry.
The problem is that at that time I was not able to fully understand the
However, reading the code now, I prefer my version using alter.
By the way, about insertWith/alter; from IntMap documentation:
alter: O(log n)
So, alter is more efficient than insertWithKey?
And what is that `W` ?
> As you've noticed, alter also allows to enforce strictness.
> But piling up appendUs is still not a good idea. For a moment,
> I thought that the stream representation's (+++) was handling
> runtime fusion gracefully, but a simple test case suggests otherwise
> at least for the simpler case of consU (the attached appendU.hs
> doesn't do any appendUs, as the consU case already demonstrates
> the issue; be careful with large numbers here, it'll quickly eat your ram):
I'm not sure to fully understand the code.
But, again, IMHO it does not apply to my original problem.
More information about the Haskell-Cafe