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).
This commit is contained in:
Simon Michael 2025-11-15 21:15:00 -10:00
parent 3d0bc53657
commit 356e2ba88a

View File

@ -303,8 +303,7 @@ includedirectivep :: MonadIO m => InputOpts -> ErroringJournalParser m ()
includedirectivep iopts = do includedirectivep iopts = do
-- save the position at start of include directive, for error messages -- save the position at start of include directive, for error messages
eoff <- getOffset eoff <- getOffset
-- and the parent file's path, for error messages and debug output pos <- getSourcePos
parentf <- getSourcePos >>= sourcePosFilePath
-- parse the directive -- parse the directive
string "include" string "include"
@ -312,6 +311,7 @@ includedirectivep iopts = do
prefixedglob <- rstrip . T.unpack <$> takeWhileP Nothing (`notElem` [';','\n']) prefixedglob <- rstrip . T.unpack <$> takeWhileP Nothing (`notElem` [';','\n'])
lift followingcommentp lift followingcommentp
let (mprefix,glb) = splitReaderPrefix prefixedglob let (mprefix,glb) = splitReaderPrefix prefixedglob
parentf <- sourcePosFilePath pos -- a little slow, don't do too often
when (null $ dbg6 (parentf <> " include: glob pattern") glb) $ when (null $ dbg6 (parentf <> " include: glob pattern") glb) $
customFailure $ parseErrorAt eoff $ "include needs a file path or glob pattern argument" 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). -- (since the parse file's path is probably always absolute).
sourcePosFilePath :: (MonadIO m) => SourcePos -> m FilePath sourcePosFilePath :: (MonadIO m) => SourcePos -> m FilePath
sourcePosFilePath = liftIO . canonicalizePath . sourceName 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 -- | Lift an IO action into the exception monad, rethrowing any IO
-- error with the given message prepended. -- error with the given message prepended.