on master help sign in
Move SmallArray to dev flag (#1783)
commit6e77cdbe2471ae45b1b77ed9140ed43a39b5ec28 authorRanjeet Ranjan <ranjeetr@composewell.com> dateThu 25 Aug 2022, 15:52 (4 years ago) parent6122ec4
10 files changed+60−54
.github/workflows/regression-check.yml−2 benchmark/NanoBenchmarks.hs+23−17 benchmark/bench-runner/Main.hs−1 benchmark/streamly-benchmarks.cabal+4−6 core/src/Streamly/Internal/Data/Array/Stream/Fold/Foreign.hs+12 core/src/Streamly/Internal/Data/Array/Unboxed/Mut/Type.hs−3 core/src/Streamly/Internal/Data/Array/Unboxed/Type.hs+5−12 core/streamly-core.cabal+5−2 streamly.cabal+10−10 test/streamly-tests.cabal+1−1
.github/workflows/regression-check.yml−2
@@ -24,9 +24,7 @@ jobs:
2424 Data.Parser
2525 Data.Parser.ParserD
2626 Data.Parser.ParserK
27− Data.SmallArray
2827 Data.Stream.StreamD
29− Data.Stream.StreamDK
3028 Data.Stream.StreamK:6
3129 Data.Unfold
3230 Data.Stream
benchmark/NanoBenchmarks.hs+23−17
@@ -6,27 +6,27 @@
66{-# LANGUAGE FlexibleContexts #-}
77{-# LANGUAGE ScopedTypeVariables #-}
88
9+import Data.Char (ord)
910import Streamly.Internal.Data.Stream (Stream)
10−import Streamly.Internal.Data.SVar (MonadAsync)
11+import System.IO (hSeek, SeekMode(..), openFile, IOMode(..))
1112
1213import qualified Streamly.Data.Array.Unboxed as A
13−import qualified Streamly.FileSystem.Handle as FH
1414import qualified Streamly.Internal.FileSystem.Handle as IFH
1515import qualified Streamly.Data.Fold as FL
16+import qualified Streamly.Internal.Data.Stream as S
1617import qualified Streamly.Internal.Data.Stream.IsStream as Internal
17−import qualified Streamly.Prelude as S
18−import qualified Streamly.Internal.Data.Stream.StreamK as K
1918
20−import Data.Char (ord)
2119import Gauge
22−import System.IO (hSeek, SeekMode(..), openFile, IOMode(..))
2320import System.Random
2421
2522maxValue :: Int
2623maxValue = 100000
2724
25+drain :: Monad m => S.Stream m a -> m ()
26+drain = S.fold FL.drain
27+
2828{-# INLINE sourceUnfoldrM #-}
29−sourceUnfoldrM :: MonadAsync m => Stream m Int
29+sourceUnfoldrM :: Monad m => Stream m Int
3030sourceUnfoldrM = S.unfoldrM step 0
3131 where
3232 step cnt =
@@ -35,7 +35,7 @@ sourceUnfoldrM = S.unfoldrM step 0
3535 else return (Just (cnt, cnt + 1))
3636
3737{-# INLINE sourceUnfoldrMN #-}
38−sourceUnfoldrMN :: MonadAsync m => Int -> Stream m Int
38+sourceUnfoldrMN :: Monad m => Int -> Stream m Int
3939sourceUnfoldrMN n = S.unfoldrM step n
4040 where
4141 step cnt =
@@ -64,7 +64,7 @@ takeAllDropOne = S.drop 1 . S.take maxValue
6464
6565{-# INLINE takeDrop #-}
6666takeDrop :: Monad m => Stream m Int -> m ()
67−takeDrop = S.drain .
67+takeDrop = drain .
6868 takeAllDropOne . takeAllDropOne . takeAllDropOne . takeAllDropOne
6969
7070-------------------------------------------------------------------------------
@@ -79,7 +79,7 @@ dropWhileFalse = S.dropWhile (> maxValue)
7979
8080{-# INLINE dropWhileFalseX4 #-}
8181dropWhileFalseX4 :: Monad m => Stream m Int -> m ()
82−dropWhileFalseX4 = S.drain
82+dropWhileFalseX4 = drain
8383 . dropWhileFalse . dropWhileFalse . dropWhileFalse . dropWhileFalse
8484
8585-------------------------------------------------------------------------------
@@ -88,7 +88,7 @@ dropWhileFalseX4 = S.drain
8888
8989{-# INLINE iterateSource #-}
9090iterateSource
91− :: MonadAsync m
91+ :: Monad m
9292 => (Stream m Int -> Stream m Int) -> Int -> Int -> Stream m Int
9393iterateSource g i n = f i (sourceUnfoldrMN n)
9494 where
@@ -100,20 +100,26 @@ iterateSource g i n = f i (sourceUnfoldrMN n)
100100main :: IO ()
101101main = do
102102 defaultMain [bench "unfoldr" $ nfIO $
103− randomRIO (1,1) >>= \n -> S.drain (sourceUnfoldr n)]
103+ randomRIO (1,1) >>= \n -> drain (sourceUnfoldr n)]
104104 defaultMain [bench "take-drop" $ nfIO $ takeDrop sourceUnfoldrM]
105105 defaultMain [bench "dropWhileFalseX4" $
106106 nfIO $ dropWhileFalseX4 sourceUnfoldrM]
107107 defaultMain [bench "iterate-mapM" $
108− nfIO $ S.drain $ iterateSource (S.mapM return) 100000 10]
108+ nfIO $ drain $ iterateSource (S.mapM return) 100000 10]
109109
110110 inText <- openFile "benchmark/text-processing/gutenberg-500.txt" ReadMode
111111 defaultMain [mkBenchText "splitOn abc...xyz" inText $ do
112− (S.length $ Internal.splitOnSeq (A.fromList $ map (fromIntegral . ord)
113− "abcdefghijklmnopqrstuvwxyz") FL.drain
114− $ IFH.getBytes inText) >>= print
112+ S.fold FL.length
113+ (Internal.splitOnSeq
114+ (A.fromList
115+ $ map (fromIntegral . ord) "abcdefghijklmnopqrstuvwxyz"
116+ )
117+ FL.drain
118+ $ IFH.getBytes inText
119+ )
120+ >>= print
115121 ]
116122 where
117123
118124 mkBenchText name h action =
119− bench name $ perRunEnv (hSeek h AbsoluteSeek 0) (\_ -> action)
125+ env (hSeek h AbsoluteSeek 0) (\_ -> bench name $ nfIO action)
benchmark/bench-runner/Main.hs−1
@@ -74,7 +74,6 @@ rtsOpts exeName benchName0 = unwords [general, exeSpecific, benchSpecific]
7474 | "Data.Parser.ParserK/o-n-heap.someAlt" == benchName = "-K4M -M128M"
7575 | "Data.Parser.ParserK/o-n-heap.sequence" == benchName = "-M64M"
7676 | "Data.Parser.ParserK/o-n-heap.sequenceA" == benchName = "-M64M"
77− | "Data.SmallArray.o-1-sp" `isPrefixOf` benchName = "-K128K"
7877 | "Data.Array" `isPrefixOf` benchName
7978 && "/o-1-space.generation.read" `isSuffixOf` benchName = "-M32M"
8079 | "Data.Array" `isPrefixOf` benchName
benchmark/streamly-benchmarks.cabal+4−6
@@ -450,10 +450,8 @@ benchmark Data.Stream.StreamDK
450450 type: exitcode-stdio-1.0
451451 hs-source-dirs: Streamly/Benchmark/Data/Stream
452452 main-is: StreamDK.hs
453− if impl(ghcjs)
453+ if !flag(dev) || impl(ghcjs)
454454 buildable: False
455− else
456− buildable: True
457455
458456executable nano-bench
459457 import: bench-options
@@ -516,10 +514,10 @@ benchmark Data.SmallArray
516514 import: bench-options
517515 type: exitcode-stdio-1.0
518516 main-is: Streamly/Benchmark/Data/Array/SmallArray.hs
519− if flag(use-streamly-core)
520− buildable: False
521− else
517+ if flag(dev) && !flag(use-streamly-core)
522518 buildable: True
519+ else
520+ buildable: False
523521
524522benchmark Data.Array.Unboxed
525523 import: bench-options
core/src/Streamly/Internal/Data/Array/Stream/Fold/Foreign.hs+12
@@ -98,7 +98,11 @@ newtype ArrayFold m a b = ArrayFold (ParserD.Parser m (Array a) b)
9898--
9999-- /Pre-release/
100100{-# INLINE fromFold #-}
101+#ifdef DEVBUILD
102+fromFold :: forall m a b. (MonadIO m) =>
103+#else
101104fromFold :: forall m a b. (MonadIO m, Unboxed a) =>
105+#endif
102106 Fold.Fold m a b -> ArrayFold m a b
103107fromFold (Fold.Fold fstep finitial fextract) =
104108 ArrayFold (ParserD.Parser step initial (fmap (Done 0) . fextract))
@@ -136,7 +140,11 @@ fromFold (Fold.Fold fstep finitial fextract) =
136140--
137141-- /Pre-release/
138142{-# INLINE fromParserD #-}
143+#ifdef DEVBUILD
144+fromParserD :: forall m a b. (MonadIO m) =>
145+#else
139146fromParserD :: forall m a b. (MonadIO m, Unboxed a) =>
147+#endif
140148 ParserD.Parser m a b -> ArrayFold m a b
141149fromParserD (ParserD.Parser step1 initial1 extract1) =
142150 ArrayFold (ParserD.Parser step initial1 extract1)
@@ -178,7 +186,11 @@ fromParserD (ParserD.Parser step1 initial1 extract1) =
178186--
179187-- /Pre-release/
180188{-# INLINE fromParser #-}
189+#ifdef DEVBUILD
190+fromParser :: forall m a b. (MonadThrow m, MonadIO m) =>
191+#else
181192fromParser :: forall m a b. (MonadThrow m, MonadIO m, Unboxed a) =>
193+#endif
182194 Parser.Parser m a b -> ArrayFold m a b
183195fromParser = fromParserD . ParserD.fromParserK
184196
core/src/Streamly/Internal/Data/Array/Unboxed/Mut/Type.hs−3
@@ -253,9 +253,6 @@ import Streamly.Internal.Data.Unfold.Type (Unfold(..))
253253import Streamly.Internal.System.IO (arrayPayloadSize, defaultChunkSize)
254254import System.IO.Unsafe (unsafePerformIO)
255255
256−#ifdef DEVBUILD
257−import qualified Data.Foldable as F
258−#endif
259256import qualified Streamly.Internal.Data.Fold.Type as FL
260257import qualified Streamly.Internal.Data.Producer as Producer
261258import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
core/src/Streamly/Internal/Data/Array/Unboxed/Type.hs+5−12
@@ -107,10 +107,6 @@ import Streamly.Internal.System.IO (unsafeInlineIO, defaultChunkSize)
107107import Data.Semigroup (Semigroup(..))
108108#endif
109109
110−#ifdef DEVBUILD
111−import qualified Data.Foldable as F
112−#endif
113−
114110--
115111-- $setup
116112-- >>> :m
@@ -563,9 +559,9 @@ instance (Unboxed a, Ord a) => Ord (Array a) where
563559-- Definitions using the Unboxed constraint from the Array type. These are to
564560-- make the Foldable instance possible though it is much slower (7x slower).
565561--
566−{-# INLINE_NORMAL toStreamD_ #-}
567−toStreamD_ :: forall m a. MonadIO m => Int -> Array a -> D.Stream m a
568−toStreamD_ size Array{..} = D.Stream step arrStart
562+{-# INLINE_NORMAL _toStreamD_ #-}
563+_toStreamD_ :: forall m a. MonadIO m => Int -> Array a -> D.Stream m a
564+_toStreamD_ size Array{..} = D.Stream step arrStart
569565
570566 where
571567
@@ -573,25 +569,22 @@ toStreamD_ size Array{..} = D.Stream step arrStart
573569 step _ p | p == arrEnd = return D.Stop
574570 step _ p = liftIO $ do
575571 x <- peekWith arrContents p
576− return $ D.Yield x (p `plusPtr` size)
572+ return $ D.Yield x (p + size)
577573
578574{-
579−
580575XXX Why isn't Unboxed implicit? This does not compile unless I use the Unboxed
581576contraint.
582−
583577{-# INLINE_NORMAL _foldr #-}
584578_foldr :: forall a b. (a -> b -> b) -> b -> Array a -> b
585579_foldr f z arr =
586580 let !n = SIZE_OF(a)
587581 in unsafePerformIO $ D.foldr f z $ toStreamD_ n arr
588−
589582-- | Note that the 'Foldable' instance is 7x slower than the direct
590583-- operations.
591584instance Foldable Array where
592585 foldr = _foldr
593−
594586-}
587+
595588#endif
596589
597590-------------------------------------------------------------------------------
core/streamly-core.cabal+5−2
@@ -265,7 +265,6 @@ library
265265 , Streamly.Internal.Data.Fold.Type
266266 , Streamly.Internal.Data.Stream.StreamD.Step
267267 , Streamly.Internal.Data.Stream.StreamD.Type
268− , Streamly.Internal.Data.Stream.StreamDK.Type
269268 , Streamly.Internal.Data.Unfold.Type
270269 , Streamly.Internal.Data.Producer.Type
271270 , Streamly.Internal.Data.Producer
@@ -293,7 +292,6 @@ library
293292 , Streamly.Internal.Data.Stream.StreamD.Exception
294293 , Streamly.Internal.Data.Stream.StreamD.Lift
295294 , Streamly.Internal.Data.Stream.StreamD
296− , Streamly.Internal.Data.Stream.StreamDK
297295 , Streamly.Internal.Data.Stream.Common
298296
299297 , Streamly.Internal.Data.Parser.ParserD.Tee
@@ -346,6 +344,11 @@ library
346344 , Streamly.Data.Array.Unboxed
347345 , Streamly.Data.Unfold
348346
347+ if flag(dev)
348+ exposed-modules:
349+ Streamly.Internal.Data.Stream.StreamDK
350+ , Streamly.Internal.Data.Stream.StreamDK.Type
351+
349352 build-depends:
350353 -- Core libraries shipped with ghc, the min and max
351354 -- constraints of these libraries should match with
streamly.cabal+10−10
@@ -430,10 +430,6 @@ library
430430
431431 Streamly.Internal.Data.IsMap.HashMap
432432
433− -- XXX To be removed or put under dev flag
434− , Streamly.Internal.Data.SmallArray.Type
435− , Streamly.Internal.Data.SmallArray
436−
437433 -- streamly-concurrent
438434 , Streamly.Internal.Data.Atomics
439435 , Streamly.Internal.Data.SVar.Worker
@@ -551,7 +547,6 @@ library
551547 , Streamly.Internal.Data.Fold.Type
552548 , Streamly.Internal.Data.Stream.StreamD.Step
553549 , Streamly.Internal.Data.Stream.StreamD.Type
554− , Streamly.Internal.Data.Stream.StreamDK.Type
555550 , Streamly.Internal.Data.Unfold.Type
556551 , Streamly.Internal.Data.Producer.Type
557552 , Streamly.Internal.Data.Producer
@@ -580,7 +575,6 @@ library
580575 , Streamly.Internal.Data.Stream.StreamD.Exception
581576 , Streamly.Internal.Data.Stream.StreamD.Lift
582577 , Streamly.Internal.Data.Stream.StreamD
583− , Streamly.Internal.Data.Stream.StreamDK
584578 , Streamly.Internal.Data.Stream.Common
585579 , Streamly.Internal.Data.Parser.ParserD.Tee
586580 , Streamly.Internal.Data.Parser.ParserD
@@ -632,8 +626,12 @@ library
632626 , Streamly.Data.Array.Unboxed
633627
634628 other-modules:
635− Streamly.Data.Array
636− , Streamly.Data.SmallArray
629+ Streamly.Data.Array
630+
631+ if flag(dev)
632+ exposed-modules: Streamly.Data.SmallArray
633+ , Streamly.Internal.Data.SmallArray
634+ , Streamly.Internal.Data.SmallArray.Type
637635
638636 if os(windows)
639637 exposed-modules: Streamly.Internal.FileSystem.Event.Windows
@@ -675,18 +673,20 @@ library
675673
676674 -- XXX to be removed
677675 , transformers-base >= 0.4 && < 0.5
678− , primitive >= 0.5.4 && < 0.8
679676 , heaps >= 0.3 && < 0.5
680677
681678 -- concurrency
682679 , atomic-primops >= 0.8 && < 0.9
683680 , lockfree-queue >= 0.2.3 && < 0.3
684−
681+
685682 , unicode-data >= 0.1 && < 0.4
686683
687684 -- Network
688685 , network >= 2.6 && < 3.2
689686
687+ if flag(dev)
688+ build-depends: primitive >= 0.5.4 && < 0.8
689+
690690 if os(windows)
691691 build-depends: Win32 >= 2.6 && < 2.13
692692
test/streamly-tests.cabal+1−1
@@ -290,7 +290,7 @@ test-suite Data.SmallArray
290290 type: exitcode-stdio-1.0
291291 main-is: Streamly/Test/Data/SmallArray.hs
292292 ghc-options: -main-is Streamly.Test.Data.SmallArray.main
293− if flag(use-streamly-core)
293+ if !flag(dev) || flag(use-streamly-core)
294294 buildable: False
295295
296296test-suite Data.Unfold