Skip to content

Commit

Permalink
perf: use module cache output from readFrom
Browse files Browse the repository at this point in the history
All of our time was being spent reading modules from the database,
because the new readFrom didn't persist its cache back to the database
state. I think originally the reason why it didn't was to avoid
state leakage, but this is safe because the module cache is guaranteed
correct (it just does JSON parsing).

Change-Id: I405069a2ee17cfb4581df20402ff66c39675d90b
  • Loading branch information
edmundnoble committed Jun 19, 2024
1 parent 6c4db9d commit 96c1d21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changes/2024-06-19T182645-0400.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a performance bug in read-only replay which was not using a cache
for module data
11 changes: 8 additions & 3 deletions src/Chainweb/Pact/Backend/RelationalCheckpointer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ doReadFrom logger v cid sql moduleCacheVar maybeParent doRead = do
Nothing -> genesisHeight v cid
Just parent -> succ . _blockHeight . _parentHeader $ parent

withMVar moduleCacheVar $ \sharedModuleCache -> do
modifyMVar moduleCacheVar $ \sharedModuleCache -> do
bracket
(beginSavepoint sql BatchSavepoint)
(\_ -> abortSavepoint sql BatchSavepoint) $ \() -> do
getEndTxId "doReadFrom" sql maybeParent >>= traverse \startTxId -> do
h <- getEndTxId "doReadFrom" sql maybeParent >>= traverse \startTxId -> do
newDbEnv <- newMVar $ BlockEnv
(mkBlockHandlerEnv v cid currentHeight sql DoNotPersistIntraBlockWrites logger)
(initBlockState defaultModuleCacheLimit startTxId)
Expand All @@ -184,7 +184,12 @@ doReadFrom logger v cid sql moduleCacheVar maybeParent doRead = do
, _cpLookupProcessedTx = \hs ->
runBlockEnv newDbEnv (doLookupSuccessful currentHeight hs)
}
doRead curBlockDbEnv
r <- doRead curBlockDbEnv
finalCache <- _bsModuleCache . _benvBlockState <$> readMVar newDbEnv
return (r, finalCache)
case h of
NoHistory -> return (sharedModuleCache, NoHistory)
Historical (r, finalCache) -> return (finalCache, Historical r)



Expand Down

0 comments on commit 96c1d21

Please sign in to comment.