From 263f4e281ae10e38178c6b77abdae9c7118e0022 Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Wed, 16 Oct 2019 13:26:34 +0300 Subject: [PATCH] Add parallelism --- koodihaaste.cabal | 2 ++ src/API.hs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/koodihaaste.cabal b/koodihaaste.cabal index cf54248..67383e9 100644 --- a/koodihaaste.cabal +++ b/koodihaaste.cabal @@ -18,6 +18,7 @@ build-type: Simple extra-source-files: CHANGELOG.md executable koodihaaste + ghc-options: -threaded -O2 -rtsopts main-is: Main.hs other-modules: Data.Language , Data.NGram @@ -45,5 +46,6 @@ executable koodihaaste , lucid , warp , yaml + , parallel hs-source-dirs: src default-language: Haskell2010 diff --git a/src/API.hs b/src/API.hs index 7008ae5..830e83b 100644 --- a/src/API.hs +++ b/src/API.hs @@ -32,6 +32,7 @@ import Servant.API import Servant.API.Generic import Servant.HTML.Lucid import Servant.Server.Generic +import Control.Parallel.Strategies import Data.Caesar import Data.Language @@ -78,7 +79,8 @@ handler = _index = do languageModel <- asks getModel sentences <- map message . bullshits <$> getBullshits - let (bullshit, noBullshit) = partitionEithers (map (findBest languageModel) sentences) + let (bullshit, noBullshit) = partitionEithers best + best = map (findBest languageModel) sentences `using` parBuffer 10 rdeepseq return $ Index noBullshit bullshit } where