mirror of
https://github.com/composewell/streamly.git
synced 2024-09-11 11:37:22 +03:00
Move SmallArray to dev flag (#1783)
This commit is contained in:
parent
6122ec4950
commit
6e77cdbe24
2
.github/workflows/regression-check.yml
vendored
2
.github/workflows/regression-check.yml
vendored
@ -24,9 +24,7 @@ jobs:
|
||||
Data.Parser
|
||||
Data.Parser.ParserD
|
||||
Data.Parser.ParserK
|
||||
Data.SmallArray
|
||||
Data.Stream.StreamD
|
||||
Data.Stream.StreamDK
|
||||
Data.Stream.StreamK:6
|
||||
Data.Unfold
|
||||
Data.Stream
|
||||
|
@ -6,27 +6,27 @@
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
|
||||
import Data.Char (ord)
|
||||
import Streamly.Internal.Data.Stream (Stream)
|
||||
import Streamly.Internal.Data.SVar (MonadAsync)
|
||||
import System.IO (hSeek, SeekMode(..), openFile, IOMode(..))
|
||||
|
||||
import qualified Streamly.Data.Array.Unboxed as A
|
||||
import qualified Streamly.FileSystem.Handle as FH
|
||||
import qualified Streamly.Internal.FileSystem.Handle as IFH
|
||||
import qualified Streamly.Data.Fold as FL
|
||||
import qualified Streamly.Internal.Data.Stream as S
|
||||
import qualified Streamly.Internal.Data.Stream.IsStream as Internal
|
||||
import qualified Streamly.Prelude as S
|
||||
import qualified Streamly.Internal.Data.Stream.StreamK as K
|
||||
|
||||
import Data.Char (ord)
|
||||
import Gauge
|
||||
import System.IO (hSeek, SeekMode(..), openFile, IOMode(..))
|
||||
import System.Random
|
||||
|
||||
maxValue :: Int
|
||||
maxValue = 100000
|
||||
|
||||
drain :: Monad m => S.Stream m a -> m ()
|
||||
drain = S.fold FL.drain
|
||||
|
||||
{-# INLINE sourceUnfoldrM #-}
|
||||
sourceUnfoldrM :: MonadAsync m => Stream m Int
|
||||
sourceUnfoldrM :: Monad m => Stream m Int
|
||||
sourceUnfoldrM = S.unfoldrM step 0
|
||||
where
|
||||
step cnt =
|
||||
@ -35,7 +35,7 @@ sourceUnfoldrM = S.unfoldrM step 0
|
||||
else return (Just (cnt, cnt + 1))
|
||||
|
||||
{-# INLINE sourceUnfoldrMN #-}
|
||||
sourceUnfoldrMN :: MonadAsync m => Int -> Stream m Int
|
||||
sourceUnfoldrMN :: Monad m => Int -> Stream m Int
|
||||
sourceUnfoldrMN n = S.unfoldrM step n
|
||||
where
|
||||
step cnt =
|
||||
@ -64,7 +64,7 @@ takeAllDropOne = S.drop 1 . S.take maxValue
|
||||
|
||||
{-# INLINE takeDrop #-}
|
||||
takeDrop :: Monad m => Stream m Int -> m ()
|
||||
takeDrop = S.drain .
|
||||
takeDrop = drain .
|
||||
takeAllDropOne . takeAllDropOne . takeAllDropOne . takeAllDropOne
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
@ -79,7 +79,7 @@ dropWhileFalse = S.dropWhile (> maxValue)
|
||||
|
||||
{-# INLINE dropWhileFalseX4 #-}
|
||||
dropWhileFalseX4 :: Monad m => Stream m Int -> m ()
|
||||
dropWhileFalseX4 = S.drain
|
||||
dropWhileFalseX4 = drain
|
||||
. dropWhileFalse . dropWhileFalse . dropWhileFalse . dropWhileFalse
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
@ -88,7 +88,7 @@ dropWhileFalseX4 = S.drain
|
||||
|
||||
{-# INLINE iterateSource #-}
|
||||
iterateSource
|
||||
:: MonadAsync m
|
||||
:: Monad m
|
||||
=> (Stream m Int -> Stream m Int) -> Int -> Int -> Stream m Int
|
||||
iterateSource g i n = f i (sourceUnfoldrMN n)
|
||||
where
|
||||
@ -100,20 +100,26 @@ iterateSource g i n = f i (sourceUnfoldrMN n)
|
||||
main :: IO ()
|
||||
main = do
|
||||
defaultMain [bench "unfoldr" $ nfIO $
|
||||
randomRIO (1,1) >>= \n -> S.drain (sourceUnfoldr n)]
|
||||
randomRIO (1,1) >>= \n -> drain (sourceUnfoldr n)]
|
||||
defaultMain [bench "take-drop" $ nfIO $ takeDrop sourceUnfoldrM]
|
||||
defaultMain [bench "dropWhileFalseX4" $
|
||||
nfIO $ dropWhileFalseX4 sourceUnfoldrM]
|
||||
defaultMain [bench "iterate-mapM" $
|
||||
nfIO $ S.drain $ iterateSource (S.mapM return) 100000 10]
|
||||
nfIO $ drain $ iterateSource (S.mapM return) 100000 10]
|
||||
|
||||
inText <- openFile "benchmark/text-processing/gutenberg-500.txt" ReadMode
|
||||
defaultMain [mkBenchText "splitOn abc...xyz" inText $ do
|
||||
(S.length $ Internal.splitOnSeq (A.fromList $ map (fromIntegral . ord)
|
||||
"abcdefghijklmnopqrstuvwxyz") FL.drain
|
||||
$ IFH.getBytes inText) >>= print
|
||||
S.fold FL.length
|
||||
(Internal.splitOnSeq
|
||||
(A.fromList
|
||||
$ map (fromIntegral . ord) "abcdefghijklmnopqrstuvwxyz"
|
||||
)
|
||||
FL.drain
|
||||
$ IFH.getBytes inText
|
||||
)
|
||||
>>= print
|
||||
]
|
||||
where
|
||||
|
||||
mkBenchText name h action =
|
||||
bench name $ perRunEnv (hSeek h AbsoluteSeek 0) (\_ -> action)
|
||||
env (hSeek h AbsoluteSeek 0) (\_ -> bench name $ nfIO action)
|
||||
|
@ -74,7 +74,6 @@ rtsOpts exeName benchName0 = unwords [general, exeSpecific, benchSpecific]
|
||||
| "Data.Parser.ParserK/o-n-heap.someAlt" == benchName = "-K4M -M128M"
|
||||
| "Data.Parser.ParserK/o-n-heap.sequence" == benchName = "-M64M"
|
||||
| "Data.Parser.ParserK/o-n-heap.sequenceA" == benchName = "-M64M"
|
||||
| "Data.SmallArray.o-1-sp" `isPrefixOf` benchName = "-K128K"
|
||||
| "Data.Array" `isPrefixOf` benchName
|
||||
&& "/o-1-space.generation.read" `isSuffixOf` benchName = "-M32M"
|
||||
| "Data.Array" `isPrefixOf` benchName
|
||||
|
@ -450,10 +450,8 @@ benchmark Data.Stream.StreamDK
|
||||
type: exitcode-stdio-1.0
|
||||
hs-source-dirs: Streamly/Benchmark/Data/Stream
|
||||
main-is: StreamDK.hs
|
||||
if impl(ghcjs)
|
||||
if !flag(dev) || impl(ghcjs)
|
||||
buildable: False
|
||||
else
|
||||
buildable: True
|
||||
|
||||
executable nano-bench
|
||||
import: bench-options
|
||||
@ -516,10 +514,10 @@ benchmark Data.SmallArray
|
||||
import: bench-options
|
||||
type: exitcode-stdio-1.0
|
||||
main-is: Streamly/Benchmark/Data/Array/SmallArray.hs
|
||||
if flag(use-streamly-core)
|
||||
buildable: False
|
||||
else
|
||||
if flag(dev) && !flag(use-streamly-core)
|
||||
buildable: True
|
||||
else
|
||||
buildable: False
|
||||
|
||||
benchmark Data.Array.Unboxed
|
||||
import: bench-options
|
||||
|
@ -98,7 +98,11 @@ newtype ArrayFold m a b = ArrayFold (ParserD.Parser m (Array a) b)
|
||||
--
|
||||
-- /Pre-release/
|
||||
{-# INLINE fromFold #-}
|
||||
#ifdef DEVBUILD
|
||||
fromFold :: forall m a b. (MonadIO m) =>
|
||||
#else
|
||||
fromFold :: forall m a b. (MonadIO m, Unboxed a) =>
|
||||
#endif
|
||||
Fold.Fold m a b -> ArrayFold m a b
|
||||
fromFold (Fold.Fold fstep finitial fextract) =
|
||||
ArrayFold (ParserD.Parser step initial (fmap (Done 0) . fextract))
|
||||
@ -136,7 +140,11 @@ fromFold (Fold.Fold fstep finitial fextract) =
|
||||
--
|
||||
-- /Pre-release/
|
||||
{-# INLINE fromParserD #-}
|
||||
#ifdef DEVBUILD
|
||||
fromParserD :: forall m a b. (MonadIO m) =>
|
||||
#else
|
||||
fromParserD :: forall m a b. (MonadIO m, Unboxed a) =>
|
||||
#endif
|
||||
ParserD.Parser m a b -> ArrayFold m a b
|
||||
fromParserD (ParserD.Parser step1 initial1 extract1) =
|
||||
ArrayFold (ParserD.Parser step initial1 extract1)
|
||||
@ -178,7 +186,11 @@ fromParserD (ParserD.Parser step1 initial1 extract1) =
|
||||
--
|
||||
-- /Pre-release/
|
||||
{-# INLINE fromParser #-}
|
||||
#ifdef DEVBUILD
|
||||
fromParser :: forall m a b. (MonadThrow m, MonadIO m) =>
|
||||
#else
|
||||
fromParser :: forall m a b. (MonadThrow m, MonadIO m, Unboxed a) =>
|
||||
#endif
|
||||
Parser.Parser m a b -> ArrayFold m a b
|
||||
fromParser = fromParserD . ParserD.fromParserK
|
||||
|
||||
|
@ -253,9 +253,6 @@ import Streamly.Internal.Data.Unfold.Type (Unfold(..))
|
||||
import Streamly.Internal.System.IO (arrayPayloadSize, defaultChunkSize)
|
||||
import System.IO.Unsafe (unsafePerformIO)
|
||||
|
||||
#ifdef DEVBUILD
|
||||
import qualified Data.Foldable as F
|
||||
#endif
|
||||
import qualified Streamly.Internal.Data.Fold.Type as FL
|
||||
import qualified Streamly.Internal.Data.Producer as Producer
|
||||
import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
|
||||
|
@ -107,10 +107,6 @@ import Streamly.Internal.System.IO (unsafeInlineIO, defaultChunkSize)
|
||||
import Data.Semigroup (Semigroup(..))
|
||||
#endif
|
||||
|
||||
#ifdef DEVBUILD
|
||||
import qualified Data.Foldable as F
|
||||
#endif
|
||||
|
||||
--
|
||||
-- $setup
|
||||
-- >>> :m
|
||||
@ -563,9 +559,9 @@ instance (Unboxed a, Ord a) => Ord (Array a) where
|
||||
-- Definitions using the Unboxed constraint from the Array type. These are to
|
||||
-- make the Foldable instance possible though it is much slower (7x slower).
|
||||
--
|
||||
{-# INLINE_NORMAL toStreamD_ #-}
|
||||
toStreamD_ :: forall m a. MonadIO m => Int -> Array a -> D.Stream m a
|
||||
toStreamD_ size Array{..} = D.Stream step arrStart
|
||||
{-# INLINE_NORMAL _toStreamD_ #-}
|
||||
_toStreamD_ :: forall m a. MonadIO m => Int -> Array a -> D.Stream m a
|
||||
_toStreamD_ size Array{..} = D.Stream step arrStart
|
||||
|
||||
where
|
||||
|
||||
@ -573,25 +569,22 @@ toStreamD_ size Array{..} = D.Stream step arrStart
|
||||
step _ p | p == arrEnd = return D.Stop
|
||||
step _ p = liftIO $ do
|
||||
x <- peekWith arrContents p
|
||||
return $ D.Yield x (p `plusPtr` size)
|
||||
return $ D.Yield x (p + size)
|
||||
|
||||
{-
|
||||
|
||||
XXX Why isn't Unboxed implicit? This does not compile unless I use the Unboxed
|
||||
contraint.
|
||||
|
||||
{-# INLINE_NORMAL _foldr #-}
|
||||
_foldr :: forall a b. (a -> b -> b) -> b -> Array a -> b
|
||||
_foldr f z arr =
|
||||
let !n = SIZE_OF(a)
|
||||
in unsafePerformIO $ D.foldr f z $ toStreamD_ n arr
|
||||
|
||||
-- | Note that the 'Foldable' instance is 7x slower than the direct
|
||||
-- operations.
|
||||
instance Foldable Array where
|
||||
foldr = _foldr
|
||||
|
||||
-}
|
||||
|
||||
#endif
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
@ -265,7 +265,6 @@ library
|
||||
, Streamly.Internal.Data.Fold.Type
|
||||
, Streamly.Internal.Data.Stream.StreamD.Step
|
||||
, Streamly.Internal.Data.Stream.StreamD.Type
|
||||
, Streamly.Internal.Data.Stream.StreamDK.Type
|
||||
, Streamly.Internal.Data.Unfold.Type
|
||||
, Streamly.Internal.Data.Producer.Type
|
||||
, Streamly.Internal.Data.Producer
|
||||
@ -293,7 +292,6 @@ library
|
||||
, Streamly.Internal.Data.Stream.StreamD.Exception
|
||||
, Streamly.Internal.Data.Stream.StreamD.Lift
|
||||
, Streamly.Internal.Data.Stream.StreamD
|
||||
, Streamly.Internal.Data.Stream.StreamDK
|
||||
, Streamly.Internal.Data.Stream.Common
|
||||
|
||||
, Streamly.Internal.Data.Parser.ParserD.Tee
|
||||
@ -346,6 +344,11 @@ library
|
||||
, Streamly.Data.Array.Unboxed
|
||||
, Streamly.Data.Unfold
|
||||
|
||||
if flag(dev)
|
||||
exposed-modules:
|
||||
Streamly.Internal.Data.Stream.StreamDK
|
||||
, Streamly.Internal.Data.Stream.StreamDK.Type
|
||||
|
||||
build-depends:
|
||||
-- Core libraries shipped with ghc, the min and max
|
||||
-- constraints of these libraries should match with
|
||||
|
@ -430,10 +430,6 @@ library
|
||||
|
||||
Streamly.Internal.Data.IsMap.HashMap
|
||||
|
||||
-- XXX To be removed or put under dev flag
|
||||
, Streamly.Internal.Data.SmallArray.Type
|
||||
, Streamly.Internal.Data.SmallArray
|
||||
|
||||
-- streamly-concurrent
|
||||
, Streamly.Internal.Data.Atomics
|
||||
, Streamly.Internal.Data.SVar.Worker
|
||||
@ -551,7 +547,6 @@ library
|
||||
, Streamly.Internal.Data.Fold.Type
|
||||
, Streamly.Internal.Data.Stream.StreamD.Step
|
||||
, Streamly.Internal.Data.Stream.StreamD.Type
|
||||
, Streamly.Internal.Data.Stream.StreamDK.Type
|
||||
, Streamly.Internal.Data.Unfold.Type
|
||||
, Streamly.Internal.Data.Producer.Type
|
||||
, Streamly.Internal.Data.Producer
|
||||
@ -580,7 +575,6 @@ library
|
||||
, Streamly.Internal.Data.Stream.StreamD.Exception
|
||||
, Streamly.Internal.Data.Stream.StreamD.Lift
|
||||
, Streamly.Internal.Data.Stream.StreamD
|
||||
, Streamly.Internal.Data.Stream.StreamDK
|
||||
, Streamly.Internal.Data.Stream.Common
|
||||
, Streamly.Internal.Data.Parser.ParserD.Tee
|
||||
, Streamly.Internal.Data.Parser.ParserD
|
||||
@ -632,8 +626,12 @@ library
|
||||
, Streamly.Data.Array.Unboxed
|
||||
|
||||
other-modules:
|
||||
Streamly.Data.Array
|
||||
, Streamly.Data.SmallArray
|
||||
Streamly.Data.Array
|
||||
|
||||
if flag(dev)
|
||||
exposed-modules: Streamly.Data.SmallArray
|
||||
, Streamly.Internal.Data.SmallArray
|
||||
, Streamly.Internal.Data.SmallArray.Type
|
||||
|
||||
if os(windows)
|
||||
exposed-modules: Streamly.Internal.FileSystem.Event.Windows
|
||||
@ -675,18 +673,20 @@ library
|
||||
|
||||
-- XXX to be removed
|
||||
, transformers-base >= 0.4 && < 0.5
|
||||
, primitive >= 0.5.4 && < 0.8
|
||||
, heaps >= 0.3 && < 0.5
|
||||
|
||||
-- concurrency
|
||||
, atomic-primops >= 0.8 && < 0.9
|
||||
, lockfree-queue >= 0.2.3 && < 0.3
|
||||
|
||||
|
||||
, unicode-data >= 0.1 && < 0.4
|
||||
|
||||
-- Network
|
||||
, network >= 2.6 && < 3.2
|
||||
|
||||
if flag(dev)
|
||||
build-depends: primitive >= 0.5.4 && < 0.8
|
||||
|
||||
if os(windows)
|
||||
build-depends: Win32 >= 2.6 && < 2.13
|
||||
|
||||
|
@ -290,7 +290,7 @@ test-suite Data.SmallArray
|
||||
type: exitcode-stdio-1.0
|
||||
main-is: Streamly/Test/Data/SmallArray.hs
|
||||
ghc-options: -main-is Streamly.Test.Data.SmallArray.main
|
||||
if flag(use-streamly-core)
|
||||
if !flag(dev) || flag(use-streamly-core)
|
||||
buildable: False
|
||||
|
||||
test-suite Data.Unfold
|
||||
|
Loading…
Reference in New Issue
Block a user