-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
memoize some cut properties in the cut record #2086
base: master
Are you sure you want to change the base?
Conversation
44bdf37
to
b09d965
Compare
@@ -357,6 +391,12 @@ projectChains m = HM.intersection m | |||
$ chainIdsAt (cutHeadersChainwebVersion m) (cutHeadersMinHeight m) | |||
{-# INLINE projectChains #-} | |||
|
|||
cutProjectChains :: Cut -> Cut | |||
cutProjectChains c = unsafeMkCut v $! projectChains $ _cutHeaders c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This $!
is unnecessary. unsafeMkCut
is strict in its second input, because _cutHeaders'
is a strict field.
True -> return $ Just | ||
$! over unsafeCutHeaders extendChains | ||
$ set (unsafeCutHeaders . ix' (_chainId h)) h c | ||
$! unsafeMkCut v | ||
$! extendChains | ||
$ set (ix' (_chainId h)) h | ||
$ _cutHeaders c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the result strict, we have to do this:
return $! Just
$! unsafeMkCut v
$ extendChains
$ set (ix' (_chainId h)) h
$ _cutHeaders c
Because return
is lazy, Just
is lazy, and extendChains
and set (ix' ...) ...
are both dealing with HashMap
s, which cannot have laziness anywhere but their elements.
-> Cut | ||
-> IO Cut | ||
limitCut wdb h c | ||
| all (\bh -> h >= view blockHeight bh) (view cutHeaders c) = | ||
return c | ||
| otherwise = do | ||
hdrs <- itraverse go $ view cutHeaders c | ||
return $! set unsafeCutHeaders (projectChains $ HM.mapMaybe id hdrs) c | ||
return $! unsafeMkCut v $! projectChains $ HM.mapMaybe id hdrs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return $! unsafeMkCut v $! projectChains $ HM.mapMaybe id hdrs | |
return $! unsafeMkCut v $ projectChains $ HM.mapMaybe id hdrs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because unsafeMkCut
is strict already.
No description provided.