mirror of
https://github.com/ilyakooo0/streamly.git
synced 2024-10-06 21:27:35 +03:00
Gain some perf by moving code out of fast path
This commit is contained in:
parent
095349d367
commit
62bca27864
@ -104,8 +104,7 @@ asyncly_basic :: IO Int
|
||||
asyncly_basic = do
|
||||
writeIORef count 0
|
||||
xs <- A.toList $ do
|
||||
-- A.each [1..1000000 :: Int]
|
||||
(A.for [1..1000000 :: Int] $ \x ->
|
||||
(A.forEachWith (A.<|) [1..1000000 :: Int] $ \x ->
|
||||
return x
|
||||
>>= afilter even
|
||||
>>= amap (+1)
|
||||
|
@ -265,6 +265,17 @@ handleException e ctx tid = do
|
||||
liftIO $ readIORef (runningThreads ctx) >>= mapM_ killThread
|
||||
throwM e
|
||||
|
||||
{-# NOINLINE sendWorkerWait #-}
|
||||
sendWorkerWait :: MonadAsync m => Context m a -> m ()
|
||||
sendWorkerWait ctx = do
|
||||
liftIO $ threadDelay 4
|
||||
let workQ = workQueue ctx
|
||||
outQ = outputQueue ctx
|
||||
workQEmpty <- liftIO $ atomically $ isEmptyTBQueue workQ
|
||||
outQEmpty <- liftIO $ atomically $ isEmptyTBQueue outQ
|
||||
when (not workQEmpty && outQEmpty) $ pushWorker ctx
|
||||
void $ liftIO $ atomically $ peekTBQueue (outputQueue ctx)
|
||||
|
||||
-- We re-raise any exceptions received from the child threads, that way
|
||||
-- exceptions get propagated to the top level computation and can be handled
|
||||
-- there.
|
||||
@ -279,15 +290,7 @@ pullWorker ctx = AsyncT $ \pctx stp yld -> do
|
||||
|
||||
res <- liftIO $ atomically $ tryReadTBQueue (outputQueue ctx)
|
||||
case res of
|
||||
Nothing -> do
|
||||
liftIO $ threadDelay 4
|
||||
let workQ = workQueue ctx
|
||||
outQ = outputQueue ctx
|
||||
workQEmpty <- liftIO $ atomically $ isEmptyTBQueue workQ
|
||||
outQEmpty <- liftIO $ atomically $ isEmptyTBQueue outQ
|
||||
when (not workQEmpty && outQEmpty) $ pushWorker ctx
|
||||
void $ liftIO $ atomically $ peekTBQueue (outputQueue ctx)
|
||||
continue
|
||||
Nothing -> sendWorkerWait ctx >> continue
|
||||
Just ev ->
|
||||
case ev of
|
||||
ChildYield a -> yield a
|
||||
|
Loading…
Reference in New Issue
Block a user