on master help sign in
Use writeN instead of write when we know the size a priori

Array write seems to perform better than writeN on smaller files that we use in the faster benchmarks. However, on larger files writeN performs better. Needless to say that the generated code for writeN is simpler than write.

commit8ce6a6dfb9c4f4ff66a77d0db3fdced22ab8fc17 authorHarendra Kumar <harendra.kumar@gmail.com> dateSun 11 Aug 2019, 15:19 (7 years ago) parent981140d
4 files changed+4−4
src/Streamly/FileSystem/Handle.hs+1−1 src/Streamly/Memory/Array/Types.hs+1−1 src/Streamly/Network/Client.hs+1−1 src/Streamly/Network/Socket.hs+1−1
src/Streamly/FileSystem/Handle.hs+1−1
@@ -330,7 +330,7 @@ writeInChunksOfS n h m = writeArraysS h $ AS.arraysOf n m
330330-- @since 0.7.0
331331{-# INLINE writeInChunksOf #-}
332332writeInChunksOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
333−writeInChunksOf n h = FL.lchunksOf n A.write (writeArrays h)
333+writeInChunksOf n h = FL.lchunksOf n (A.writeN n) (writeArrays h)
334334
335335-- > write = 'writeInChunksOf' A.defaultChunkSize
336336--
src/Streamly/Memory/Array/Types.hs+1−1
@@ -491,7 +491,7 @@ writeN n = Fold step initial extract
491491 step (Array start end bound) x = do
492492 liftIO $ poke end x
493493 return $ Array start (end `plusPtr` sizeOf (undefined :: a)) bound
494− extract = liftIO . shrinkToFit
494+ extract = return -- liftIO . shrinkToFit
495495
496496{-# INLINE_NORMAL fromStreamDN #-}
497497fromStreamDN :: forall m a. (MonadIO m, Storable a)
src/Streamly/Network/Client.hs+1−1
@@ -180,7 +180,7 @@ writeInChunksOf
180180 -> (Word8, Word8, Word8, Word8)
181181 -> PortNumber
182182 -> Fold m Word8 ()
183−writeInChunksOf n addr port = FL.lchunksOf n A.write (writeArrays addr port)
183+writeInChunksOf n addr port = FL.lchunksOf n (A.writeN n) (writeArrays addr port)
184184
185185{-
186186-- | Write a stream to the supplied IPv4 host address and port number.
src/Streamly/Network/Socket.hs+1−1
@@ -310,7 +310,7 @@ writeInChunksOfS n h m = writeArraysS h $ AS.arraysOf n m
310310-- @since 0.7.0
311311{-# INLINE writeInChunksOf #-}
312312writeInChunksOf :: MonadIO m => Int -> Socket -> Fold m Word8 ()
313−writeInChunksOf n h = FL.lchunksOf n A.write (writeArrays h)
313+writeInChunksOf n h = FL.lchunksOf n (A.writeN n) (writeArrays h)
314314
315315-- > write = 'writeInChunksOf' A.defaultChunkSize
316316--