diff --git a/app/Main.hs b/app/Main.hs index 7ccf158..265adf1 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -13,6 +13,9 @@ module Main (main) where +import Control.DeepSeq (force) +import Control.Exception (evaluate) +import Control.Monad (void) import Data.Char (chr) import Data.FileEmbed (embedFile) import Data.Foldable (for_) @@ -55,7 +58,12 @@ import qualified UToy.Names as Names import qualified UToy.Parsers as Parsers main :: IO () -main = Warp.run 3000 app +main = do + -- Forced evaluation of Names.lowerNames to reduce number of thunks. + putStrLn "* Building search index" + void $ evaluate $ force Names.lowerNames + putStrLn "* Listening on http://localhost:3000" + Warp.run 3000 app app :: Application app = serve (Proxy :: Proxy API) server diff --git a/src/UToy/Names.hs b/src/UToy/Names.hs index 33d9c13..03aa620 100644 --- a/src/UToy/Names.hs +++ b/src/UToy/Names.hs @@ -1,4 +1,4 @@ -module UToy.Names (allNames, blockName, searchCaseInsensitive) where +module UToy.Names (allNames, blockName, lowerNames, searchCaseInsensitive) where import Data.Char (ord) import Data.Maybe (maybeToList) @@ -25,7 +25,7 @@ searchCaseInsensitive search = filter go [minBound..maxBound] go c = any matches $ Vector.unsafeIndex lowerNames (ord c - ord minBound) matches t = Text.toLower search `Text.isInfixOf` t -lowerNames :: Vector [Text] +lowerNames :: Vector (Vector Text) lowerNames = Vector.fromList $ map go [minBound..maxBound] where - go = map Text.toLower . allNames + go = Vector.fromList . map Text.toLower . allNames diff --git a/utoy.cabal b/utoy.cabal index 82f9ea2..5215eb8 100644 --- a/utoy.cabal +++ b/utoy.cabal @@ -46,6 +46,7 @@ executable utoy , base >=4.7 && <5 , blaze-html , bytestring + , deepseq , file-embed , http-media , servant-server