From 356e2ba88a531fb0060ec20bbd55d0da9e458a43 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 15 Nov 2025 21:15:00 -1000 Subject: [PATCH] fix:journal: repair 1.50's journal reading slowness [#2493] Since 1.50, sourceFilePath, which does IO operations, was being called for every item in the journal. On my machine this was causing a ~40% slowdown, but probably it could be more depending on storage system. Now it's once again called only once per include directive. Speed seems slightly better now than 1.43 for some reason (eg: 13k txns/s -> 8k txns/s -> 14k txns/s). --- hledger-lib/Hledger/Read/JournalReader.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index c22441099..579bf92de 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -303,8 +303,7 @@ includedirectivep :: MonadIO m => InputOpts -> ErroringJournalParser m () includedirectivep iopts = do -- save the position at start of include directive, for error messages eoff <- getOffset - -- and the parent file's path, for error messages and debug output - parentf <- getSourcePos >>= sourcePosFilePath + pos <- getSourcePos -- parse the directive string "include" @@ -312,6 +311,7 @@ includedirectivep iopts = do prefixedglob <- rstrip . T.unpack <$> takeWhileP Nothing (`notElem` [';','\n']) lift followingcommentp let (mprefix,glb) = splitReaderPrefix prefixedglob + parentf <- sourcePosFilePath pos -- a little slow, don't do too often when (null $ dbg6 (parentf <> " include: glob pattern") glb) $ customFailure $ parseErrorAt eoff $ "include needs a file path or glob pattern argument" @@ -496,6 +496,8 @@ includedirectivep iopts = do -- (since the parse file's path is probably always absolute). sourcePosFilePath :: (MonadIO m) => SourcePos -> m FilePath sourcePosFilePath = liftIO . canonicalizePath . sourceName +-- "canonicalizePath is a very big hammer. If you only need an absolute path, makeAbsolute is sufficient" +-- but we only do this once per include directive, seems ok to leave it as is. -- | Lift an IO action into the exception monad, rethrowing any IO -- error with the given message prepended.