diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2017-11-21 18:20:05 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-11-21 09:20:05 -0800 |
commit | 30c1e53c42b4829c6eac9ab55d66fac6411c2c71 (patch) | |
tree | dab64804040f8972644db57c0b66ada10e42d30b /src/Text/Pandoc | |
parent | 185918ea3d5ad759d7050e8ccb638734231e6762 (diff) | |
download | pandoc-30c1e53c42b4829c6eac9ab55d66fac6411c2c71.tar.gz |
Change JSON instances for Opt to TemplateHaskell (#4083)
The `Generic` JSON instances for `Text.Pandoc.App.Opt` seem to tickle a
particulary bad quadratic complexity case (Generics complexity is worse
than quadratic with respect to the number of fields in the datatype).
This is with GHC-8.2.1, I didn't test it using 8.0 but I assume it is
similar.
Using `Generic`, compilation of the `Text.Pandoc.App` module takes
minutes and often gets killed due to out of memory on slower machines
with "only" 8GB of accessible memory. This is particularly annoying to
me since it means I cannot build pandoc on Travis.
TemplateHaskell is a little uglier, but the module seems to compile
within a few seconds, and compilation doesn't take more than 1GB of
memory.
Should I also change the other JSON instances throughout the codebase
for consistency?
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/App.hs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs index d9f92335c..4c4525dce 100644 --- a/src/Text/Pandoc/App.hs +++ b/src/Text/Pandoc/App.hs @@ -1,6 +1,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TupleSections #-} {- Copyright (C) 2006-2017 John MacFarlane <jgm@berkeley.edu> @@ -44,8 +45,8 @@ import qualified Control.Exception as E import Control.Monad import Control.Monad.Except (catchError, throwError) import Control.Monad.Trans -import Data.Aeson (FromJSON (..), ToJSON (..), defaultOptions, eitherDecode', - encode, genericToEncoding) +import Data.Aeson (defaultOptions, eitherDecode', encode) +import Data.Aeson.TH (deriveJSON) import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as B import Data.Char (toLower, toUpper) @@ -95,10 +96,6 @@ import System.Posix.Terminal (queryTerminal) data LineEnding = LF | CRLF | Native deriving (Show, Generic) -instance ToJSON LineEnding where - toEncoding = genericToEncoding defaultOptions -instance FromJSON LineEnding - parseOptions :: [OptDescr (Opt -> IO Opt)] -> Opt -> IO Opt parseOptions options' defaults = do rawArgs <- map UTF8.decodeArg <$> getArgs @@ -646,10 +643,6 @@ data Opt = Opt , optStripComments :: Bool -- ^ Skip HTML comments } deriving (Generic, Show) -instance ToJSON Opt where - toEncoding = genericToEncoding defaultOptions -instance FromJSON Opt - -- | Defaults for command-line options. defaultOpts :: Opt defaultOpts = Opt @@ -1677,3 +1670,6 @@ deprecatedOption o = \r -> case r of Right () -> return () Left e -> E.throwIO e + +$(deriveJSON defaultOptions ''LineEnding) +$(deriveJSON defaultOptions ''Opt) |