Skip to content

Commit 356e2ba

Browse files
committed
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).
1 parent 3d0bc53 commit 356e2ba

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

hledger-lib/Hledger/Read/JournalReader.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,15 @@ includedirectivep :: MonadIO m => InputOpts -> ErroringJournalParser m ()
303303
includedirectivep iopts = do
304304
-- save the position at start of include directive, for error messages
305305
eoff <- getOffset
306-
-- and the parent file's path, for error messages and debug output
307-
parentf <- getSourcePos >>= sourcePosFilePath
306+
pos <- getSourcePos
308307

309308
-- parse the directive
310309
string "include"
311310
lift skipNonNewlineSpaces1
312311
prefixedglob <- rstrip . T.unpack <$> takeWhileP Nothing (`notElem` [';','\n'])
313312
lift followingcommentp
314313
let (mprefix,glb) = splitReaderPrefix prefixedglob
314+
parentf <- sourcePosFilePath pos -- a little slow, don't do too often
315315
when (null $ dbg6 (parentf <> " include: glob pattern") glb) $
316316
customFailure $ parseErrorAt eoff $ "include needs a file path or glob pattern argument"
317317

@@ -496,6 +496,8 @@ includedirectivep iopts = do
496496
-- (since the parse file's path is probably always absolute).
497497
sourcePosFilePath :: (MonadIO m) => SourcePos -> m FilePath
498498
sourcePosFilePath = liftIO . canonicalizePath . sourceName
499+
-- "canonicalizePath is a very big hammer. If you only need an absolute path, makeAbsolute is sufficient"
500+
-- but we only do this once per include directive, seems ok to leave it as is.
499501

500502
-- | Lift an IO action into the exception monad, rethrowing any IO
501503
-- error with the given message prepended.

0 commit comments

Comments
 (0)