lib: textification: saved journal source

Slightly worse on small files, better on large ones.

hledger -f data/100x100x10.journal stats
<<ghc: 39305392 bytes, 77 GCs, 196354/268584 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.007 elapsed), 0.014 MUT (0.027 elapsed), 0.011 GC (0.111 elapsed) :ghc>>
<<ghc: 39307728 bytes, 77 GCs, 196909/270248 avg/max bytes residency (3 samples), 2M in use, 0.001 INIT (0.010 elapsed), 0.015 MUT (0.028 elapsed), 0.012 GC (0.116 elapsed) :ghc>>

hledger -f data/1000x1000x10.journal stats
<<ghc: 314285912 bytes, 612 GCs, 2064811/6597608 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.002 elapsed), 0.126 MUT (0.134 elapsed), 0.059 GC (0.069 elapsed) :ghc>>
<<ghc: 314271368 bytes, 612 GCs, 2070227/6628024 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.000 elapsed), 0.137 MUT (0.143 elapsed), 0.059 GC (0.068 elapsed) :ghc>>

hledger -f data/10000x1000x10.journal stats
<<ghc: 3070033264 bytes, 5965 GCs, 12699294/62962464 avg/max bytes residency (10 samples), 124M in use, 0.000 INIT (0.000 elapsed), 1.245 MUT (1.300 elapsed), 0.498 GC (0.558 elapsed) :ghc>>
<<ghc: 3070006752 bytes, 5973 GCs, 12687314/62848920 avg/max bytes residency (10 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.257 MUT (1.281 elapsed), 0.496 GC (0.554 elapsed) :ghc>>

hledger -f data/100000x1000x10.journal stats
<<ghc: 30753465088 bytes, 59763 GCs, 117723618/666643528 avg/max bytes residency (14 samples), 1589M in use, 0.000 INIT (0.002 elapsed), 12.536 MUT (12.793 elapsed), 5.978 GC (7.155 elapsed) :ghc>>
<<ghc: 30753367256 bytes, 59811 GCs, 117723236/666627528 avg/max bytes residency (14 samples), 1590M in use, 0.001 INIT (0.012 elapsed), 12.923 MUT (13.169 elapsed), 5.981 GC (6.860 elapsed) :ghc>>
This commit is contained in:
Simon Michael 2016-05-23 19:24:39 -07:00
parent 102b76c17f
commit 58c3362908
4 changed files with 8 additions and 8 deletions

View File

@ -63,7 +63,7 @@ import Data.List
import Data.Maybe import Data.Maybe
import Data.Monoid import Data.Monoid
import Data.Ord import Data.Ord
-- import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as T import qualified Data.Text as T
import Safe (headMay, headDef) import Safe (headMay, headDef)
import Data.Time.Calendar import Data.Time.Calendar
@ -185,7 +185,7 @@ journalFilePath = fst . mainfile
journalFilePaths :: Journal -> [FilePath] journalFilePaths :: Journal -> [FilePath]
journalFilePaths = map fst . jfiles journalFilePaths = map fst . jfiles
mainfile :: Journal -> (FilePath, String) mainfile :: Journal -> (FilePath, Text)
mainfile = headDef ("", "") . jfiles mainfile = headDef ("", "") . jfiles
addTransaction :: Transaction -> Journal -> Journal addTransaction :: Transaction -> Journal -> Journal
@ -455,7 +455,7 @@ journalApplyAliases aliases j@Journal{jtxns=ts} =
-- use. Reverse parsed data to normal order, canonicalise amount -- use. Reverse parsed data to normal order, canonicalise amount
-- formats, check/ensure that transactions are balanced, and maybe -- formats, check/ensure that transactions are balanced, and maybe
-- check balance assertions. -- check balance assertions.
journalFinalise :: ClockTime -> FilePath -> String -> Bool -> ParsedJournal -> Either String Journal journalFinalise :: ClockTime -> FilePath -> Text -> Bool -> ParsedJournal -> Either String Journal
journalFinalise t path txt assrt j@Journal{jfiles=fs} = do journalFinalise t path txt assrt j@Journal{jfiles=fs} = do
(journalBalanceTransactions $ (journalBalanceTransactions $
journalApplyCommodityStyles $ journalApplyCommodityStyles $

View File

@ -251,7 +251,7 @@ data Journal = Journal {
,jperiodictxns :: [PeriodicTransaction] ,jperiodictxns :: [PeriodicTransaction]
,jtxns :: [Transaction] ,jtxns :: [Transaction]
,jfinalcommentlines :: String -- ^ any final trailing comments in the (main) journal file ,jfinalcommentlines :: String -- ^ any final trailing comments in the (main) journal file
,jfiles :: [(FilePath, String)] -- ^ the file path and raw text of the main and ,jfiles :: [(FilePath, Text)] -- ^ the file path and raw text of the main and
-- any included journal files. The main file is first, -- any included journal files. The main file is first,
-- followed by any included files in the order encountered. -- followed by any included files in the order encountered.
,jlastreadtime :: ClockTime -- ^ when this journal was last read from its file(s) ,jlastreadtime :: ClockTime -- ^ when this journal was last read from its file(s)

View File

@ -27,7 +27,7 @@ import Data.Functor.Identity
import Data.List.Compat import Data.List.Compat
import Data.List.Split (wordsBy) import Data.List.Split (wordsBy)
import Data.Maybe import Data.Maybe
-- import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as T import qualified Data.Text as T
import Data.Time.Calendar import Data.Time.Calendar
import Data.Time.LocalTime import Data.Time.LocalTime
@ -76,7 +76,7 @@ parseAndFinaliseJournal parser assrt f s = do
y <- liftIO getCurrentYear y <- liftIO getCurrentYear
ep <- runParserT parser nulljournal{jparsedefaultyear=Just y} f s ep <- runParserT parser nulljournal{jparsedefaultyear=Just y} f s
case ep of case ep of
Right pj -> case journalFinalise t f s assrt pj of Right pj -> case journalFinalise t f (T.pack s) assrt pj of
Right j -> return j Right j -> return j
Left e -> throwError e Left e -> throwError e
Left e -> throwError $ show e Left e -> throwError $ show e
@ -130,7 +130,7 @@ incrementTransactionCount = do
modifyState (\j -> j{jparsetransactioncount=jparsetransactioncount j + 1}) modifyState (\j -> j{jparsetransactioncount=jparsetransactioncount j + 1})
getTransactionCount getTransactionCount
journalAddFile :: (FilePath,String) -> Journal -> Journal journalAddFile :: (FilePath,Text) -> Journal -> Journal
journalAddFile f j@Journal{jfiles=fs} = j{jfiles=fs++[f]} journalAddFile f j@Journal{jfiles=fs} = j{jfiles=fs++[f]}
-- append, unlike the other fields, even though we do a final reverse, -- append, unlike the other fields, even though we do a final reverse,
-- to compensate for additional reversal due to including/monoid-concatting -- to compensate for additional reversal due to including/monoid-concatting

View File

@ -203,7 +203,7 @@ includedirectivep = do
(throwError (throwError
. ((show parentpos ++ " in included file " ++ show filename ++ ":\n") ++) . ((show parentpos ++ " in included file " ++ show filename ++ ":\n") ++)
. show) . show)
(return . journalAddFile (filepath,txt)) (return . journalAddFile (filepath, T.pack txt))
ej1 ej1
case ej of case ej of
Left e -> throwError e Left e -> throwError e