
Converting to Ptr Word8 and storables took about an hour and gave me a more favorable profile. COST CENTRE MODULE %time %alloc reverse_ Script.Endian 14.4 13.4 sequ Script.Pickle 14.3 9.3 read Script.PokerClient 10.9 9.1 storable Script.Pickle 10.8 10.7 timestamp Script.Trace 7.1 3.8 dispatch Script.Engine 6.3 4.3 unstuff Script.PokerClient 4.4 2.9 appU_wstr Script.Endian 4.4 3.2 trace_ Script.Trace 3.9 1.2 readQ Script.Queue 3.3 13.0 lift Script.Pickle 2.9 5.3 writeQ Script.Queue 2.8 2.7 wrap Script.Pickle 2.2 1.2 $!! Script.DeepSeq 1.8 0.5 puTableInfo Script.PicklePlus 1.7 2.6 puCommand Script.PickleCmd 1.1 0.1 fetch Script.Engine 0.9 11.6 post_ Script.Engine 0.2 1.7 Any suggestions on how to optimize reverseBytes below? Would specializing it help? isBigEndian :: Bool isBigEndian = $(lift $ (1::CChar) /= (unsafePerformIO $ with (1::CInt) $ peekByteOff `flip` 0) ) :: Bool reverse_ :: (Storable a, Endian a) => a -> a reverse_ a = if isBigEndian then reverseBytes a else a --- Endian conversion class (Bits a, Integral a, Num a) => Endian a where reverseBytes :: a -> a instance Endian Word16 where reverseBytes v = (v `shiftR` 8) + ((v .&. 0xFF) `shiftL` 8) instance Endian Int16 where reverseBytes v = (v `shiftR` 8) + ((v .&. 0xFF) `shiftL` 8) instance Endian Word32 where reverseBytes v = ( v `shiftR` 24) + ((v .&. 0x000000FF) `shiftL` 24) + ((v .&. 0x0000FF00) `shiftL` 8) + ((v .&. 0x00FF0000) `shiftR` 8) instance Endian Int32 where reverseBytes v = ( v `shiftR` 24) + ((v .&. 0x000000FF) `shiftL` 24) + ((v .&. 0x0000FF00) `shiftL` 8) + ((v .&. 0x00FF0000) `shiftR` 8) instance Endian Word64 where reverseBytes v = ( v `shiftR` 56) + ((v .&. 0x00000000000000FF) `shiftL` 56) + ((v .&. 0x00FF000000000000) `shiftR` 40) + ((v .&. 0x000000000000FF00) `shiftL` 40) + ((v .&. 0x0000FF0000000000) `shiftR` 24) + ((v .&. 0x0000000000FF0000) `shiftL` 24) + ((v .&. 0x000000FF00000000) `shiftR` 8) + ((v .&. 0x00000000FF000000) `shiftL` 8) -- http://wagerlabs.com/