Gain some perf by moving code out of fast path

This commit is contained in:
Harendra Kumar 2017-08-30 03:10:53 +05:30
parent 095349d367
commit 62bca27864
2 changed files with 13 additions and 11 deletions

View File

@ -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)

View File

@ -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