[Haskell-cafe] Array performance is killing me

Joel Reymont joelr1 at gmail.com
Mon Dec 19 14:04:41 EST 2005


I managed to reduce my memory consumption but I have a performance  
problem now. This is a profiling report from my app. -O was not  
supplied when compiling the library and the relevant modules are at  

COST CENTRE                    MODULE               %time %alloc
byteArrayFromPtr               Script.Array          39.1   43.9
readBits                       Script.Array          23.6   25.5
emptyByteArray                 Script.Array           7.6    6.0
endian#2                       Script.Endian          4.4    4.2
bytearray                      Script.Pickle          3.9    3.4
copyMArray                     Script.Array           2.8    3.4
sequ                           Script.Pickle          2.7    2.0
withByteArray                  Script.Array           2.3    2.1
num#2                          Script.Pickle          1.3    1.7
wstr#5                         Script.Endian          1.1    0.6
byteSize                       Script.Pickle          1.1    0.5

I run into trouble with packets of ~50K that consist of a header (a  
few bytes) and compressed data. The compressed data has to be  
uncompressed and then parsed again. Overall, this takes a copy from  
array (I use hGetArray) into Ptr Word8 to be supplied to ZLib's  
compress and then another copy from Ptr Word8 into a byte array for  

readBits is supposed to extract numbers from a byte array and can be  
found in Array.hs. uncompress is in ZLib.hs and the endian bits in  
Endian.hs. The code should compile without problems.

Please help me optimize this!

	Thanks, Joel


More information about the Haskell-Cafe mailing list