on master help sign in
Speedup of factor 4 by switching to the Data.Binary library for serialization.
cf789c7Jasper Van der Jeugt
hakyll.cabal+2−1
@@ -34,7 +34,8 @@ library
34 mtl >= 1.1,
34 mtl >= 1.1,
35 old-locale >= 1,
35 old-locale >= 1,
36 time >= 1,
36 time >= 1,
37− parallel >= 2
37+ parallel >= 2,
38+ binary >= 0.5
38 exposed-modules: Text.Hakyll
39 exposed-modules: Text.Hakyll
39 Text.Hakyll.Hakyll
40 Text.Hakyll.Hakyll
40 Text.Hakyll.Render
41 Text.Hakyll.Render
src/Text/Hakyll/Internal/Cache.hs+5−7
@@ -6,19 +6,17 @@ module Text.Hakyll.Internal.Cache
6import Control.Monad.Reader (liftIO)
6import Control.Monad.Reader (liftIO)
7import Text.Hakyll.Hakyll (Hakyll)
7import Text.Hakyll.Hakyll (Hakyll)
8import Text.Hakyll.File
8import Text.Hakyll.File
9+import Data.Binary
9
10
10−storeInCache :: (Show a) => a -> FilePath -> Hakyll ()
11+storeInCache :: (Binary a) => a -> FilePath -> Hakyll ()
11storeInCache value path = do
12storeInCache value path = do
12 cachePath <- toCache path
13 cachePath <- toCache path
13 makeDirectories cachePath
14 makeDirectories cachePath
14− liftIO $ writeFile cachePath (show value)
15+ liftIO $ encodeFile cachePath value
15
16
16−getFromCache :: (Read a) => FilePath -> Hakyll (Maybe a)
17+getFromCache :: (Binary a) => FilePath -> Hakyll (Maybe a)
17getFromCache path = do
18getFromCache path = do
18 cachePath <- toCache path
19 cachePath <- toCache path
19 valid <- isMoreRecent cachePath [path]
20 valid <- isMoreRecent cachePath [path]
20− if valid then liftIO (getFromCache' cachePath) >>= return . Just
21+ if valid then liftIO (decodeFile cachePath) >>= return . Just
21 else return Nothing
22 else return Nothing
22− where
23− getFromCache' cachePath = do c <- readFile cachePath
24− return (read c)
src/Text/Hakyll/Page.hs+8−1
@@ -11,12 +11,14 @@ import qualified Data.Map as M
11import Data.List (isPrefixOf)
11import Data.List (isPrefixOf)
12import Data.Char (isSpace)
12import Data.Char (isSpace)
13import Data.Maybe (fromMaybe)
13import Data.Maybe (fromMaybe)
14−import Control.Parallel.Strategies (rdeepseq, ($|))
14+import Control.Monad (liftM)
15import Control.Monad.Reader (liftIO)
15import Control.Monad.Reader (liftIO)
16+import Control.Parallel.Strategies (rdeepseq, ($|))
16import System.FilePath (takeExtension)
17import System.FilePath (takeExtension)
17import System.IO
18import System.IO
18
19
19import Text.Pandoc
20import Text.Pandoc
21+import Data.Binary
20
22
21import Text.Hakyll.Internal.Cache
23import Text.Hakyll.Internal.Cache
22import Text.Hakyll.Hakyll (Hakyll)
24import Text.Hakyll.Hakyll (Hakyll)
@@ -148,3 +150,8 @@ instance Renderable Page where
148 getDependencies = (:[]) . getPagePath
150 getDependencies = (:[]) . getPagePath
149 getURL = getPageURL
151 getURL = getPageURL
150 toContext (Page page) = return page
152 toContext (Page page) = return page
153+
154+-- Make pages serializable.
155+instance Binary Page where
156+ put (Page context) = put $ M.toList context
157+ get = liftM (Page . M.fromList) get