From a8a9d250e312bc04e2da1edcf641af8dce9773c7 Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Fri, 13 May 2016 14:46:23 -0400 Subject: [PATCH] Parallelize search Why? ==== Searching hundreds or thousands of tokens with ag can be slow; this introduces parallel processing of search so results are returned more quickly. --- src/Unused/CLI/ProgressIndicator.hs | 3 ++- unused.cabal | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Unused/CLI/ProgressIndicator.hs b/src/Unused/CLI/ProgressIndicator.hs index 71d8a6b..046a8a2 100644 --- a/src/Unused/CLI/ProgressIndicator.hs +++ b/src/Unused/CLI/ProgressIndicator.hs @@ -5,6 +5,7 @@ module Unused.CLI.ProgressIndicator , progressWithIndicator ) where +import Control.Concurrent.ParallelIO import Unused.CLI.Util import Unused.CLI.ProgressIndicator.Types import Unused.CLI.ProgressIndicator.Internal @@ -23,6 +24,6 @@ progressWithIndicator :: (a -> IO [b]) -> ProgressIndicator -> [a] -> IO [b] progressWithIndicator f i terms = do printPrefix i indicator <- start i $ length terms - concat <$> sequence (ioOps indicator) <* stop indicator + concat <$> parallel (ioOps indicator) <* stop indicator <* stopGlobalPool where ioOps i' = map (\t -> f t <* increment i') terms diff --git a/unused.cabal b/unused.cabal index cf0f7c3..4df36d0 100644 --- a/unused.cabal +++ b/unused.cabal @@ -42,6 +42,7 @@ library , terminal-progress-bar , ansi-terminal , unix + , parallel-io ghc-options: -Wall -Werror -O2 default-language: Haskell2010