Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple PRs #2662

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion benchmark/Streamly/Benchmark/Unicode/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Streamly.Data.Stream (Stream)
import Streamly.Data.Fold (Fold)
import Prelude hiding (last, length)
import System.IO (Handle)
import Streamly.Internal.System.IO (arrayPayloadSize)

import qualified Streamly.Data.Array as Array
import qualified Streamly.Data.Fold as Fold
Expand All @@ -37,6 +38,7 @@ import qualified Streamly.Internal.Data.Unfold as Unfold
import qualified Streamly.Internal.FileSystem.Handle as Handle
import qualified Streamly.Internal.Unicode.Array as UnicodeArr
import qualified Streamly.Internal.Unicode.Stream as Unicode
import qualified Streamly.Internal.Data.Array as Array

import Test.Tasty.Bench hiding (env)
import Streamly.Benchmark.Common
Expand All @@ -45,7 +47,6 @@ import Streamly.Benchmark.Common.Handle
#ifdef INSPECTION
import Streamly.Internal.Data.MutByteArray (Unbox)
import Streamly.Internal.Data.Stream (Step(..))
import qualified Streamly.Internal.Data.Array as Array
import qualified Streamly.Internal.Data.MutArray as MutArray
import qualified Streamly.Internal.Data.Fold as Fold
import qualified Streamly.Internal.Data.Tuple.Strict as Strict
Expand Down Expand Up @@ -258,6 +259,17 @@ _copyStreamUtf8' inh outh =
$ Unicode.decodeUtf8'
$ Stream.unfold Handle.reader inh

-- | Copy file
{-# NOINLINE copyStreamUtf16 #-}
copyStreamUtf16 :: Handle -> Handle -> IO ()
copyStreamUtf16 inh outh =
Stream.fold (Handle.writeChunks outh)
$ fmap Array.castUnsafe $ Array.chunksOf (arrayPayloadSize (16 * 1024))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use defaultChunkSize instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the number of elements constant for comparison.

$ Unicode.encodeUtf16le'
$ Unicode.decodeUtf16le
$ Array.concat $ fmap Array.castUnsafe $ Unicode.mkEvenW8Chunks
$ Handle.readChunks inh

#ifdef INSPECTION
inspect $ hasNoTypeClasses '_copyStreamUtf8'
-- inspect $ '_copyStreamUtf8 `hasNoType` ''Step
Expand Down Expand Up @@ -319,6 +331,8 @@ o_1_space_decode_encode_read env =
$ \inh outh -> _copyStreamUtf8Parser inh outh
, mkBenchSmall "encodeUtf8 . decodeUtf8" env $ \inh outh ->
copyStreamUtf8 inh outh
, mkBenchSmall "encodeUtf16 . decodeUtf16" env $ \inh outh ->
copyStreamUtf16 inh outh
]
]

Expand Down
29 changes: 0 additions & 29 deletions core/src/Streamly/Internal/Data/Array/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ module Streamly.Internal.Data.Array.Type
-- ** Construction
, empty

-- *** Cloning
-- XXX Why would we clone an immutable array?
, clone
, pinnedClone

-- *** Slicing
-- | Get a subarray without copying
, splitAt
Expand Down Expand Up @@ -415,30 +410,6 @@ fromStreamD :: forall m a. (MonadIO m, Unbox a)
=> D.Stream m a -> m (Array a)
fromStreamD = fromStream

-------------------------------------------------------------------------------
-- Cloning
-------------------------------------------------------------------------------

{-# INLINE clone #-}
clone ::
( MonadIO m
#ifdef DEVBUILD
, Unbox a
#endif
)
=> Array a -> m (Array a)
clone = fmap unsafeFreeze . MA.clone . unsafeThaw

{-# INLINE pinnedClone #-}
pinnedClone ::
( MonadIO m
#ifdef DEVBUILD
, Unbox a
#endif
)
=> Array a -> m (Array a)
pinnedClone = fmap unsafeFreeze . MA.pinnedClone . unsafeThaw

-------------------------------------------------------------------------------
-- Streams of arrays
-------------------------------------------------------------------------------
Expand Down
Loading
Loading