-
Notifications
You must be signed in to change notification settings - Fork 155
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
Sharing of values during deserialization #2557
Conversation
590209e
to
ec64c42
Compare
A bit of an overview might help. As I see it, we introduce a new class, The old PR #2548 dose similar things, but does them explicitly and manually. we trade lifting and monads, for pattern matching over tuples, and for explicit state transformers: fromCBORShare :: state -> (Decoder, state) in the few places it is needed. |
7b5ea27
to
e0b3fb3
Compare
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.
Made a bunch of comments, but otherwise I think this looks good!
decodeRecordNamed "DPState" (const 2) $ DPState <$> fromCBOR <*> fromCBOR | ||
toCBOR DPState {_pstate, _dstate} = | ||
encodeListLen 2 | ||
<> toCBOR _pstate -- We get better sharing when encoding pstate before dstate |
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.
OK, so we need to rebuild the ledger state. We should definitely coordinate the changes with the other things that update the ledger state serialisation.
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.
Most definitely! We should talk about this, cause I am not sure what is the process when CBOR is changed in a backwards incompatible manner
@@ -14,7 +14,10 @@ import System.IO | |||
data Opts = Opts | |||
{ -- | Path to the CBOR encoded NewEpochState data type, which will be used to | |||
-- load into sqlite database | |||
optsLedgerStateBinaryFile :: Maybe FilePath, | |||
optsNewEpochStateBinaryFile :: Maybe FilePath, |
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.
Duplicate options?
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.
Do you mean options in bench
and app
are the same? If that's the question than they look the same but they mean different things (eg. one is for reading, while another one is for writing). Moreover I suspect they will diverge in the future.
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.
I meant as with the other comment, sounds like it's addressed
-- let dbFp = T.pack dbFpStr | ||
-- km <- loadDbUTxO txIdSharingKeyMap dbFp | ||
-- m <- loadDbUTxO noSharing dbFp | ||
-- testKeyMap km m |
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.
Dead code?
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.
It can still be useful. I will do a final cleanup of ledger-state package once we are done with memory optimizations
optsNewEpochStateBinaryFile :: Maybe FilePath, | ||
-- | Path to the CBOR encoded EpochState data type, which will be used to | ||
-- load into sqlite database | ||
optsEpochStateBinaryFile :: Maybe FilePath, |
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.
Ditto comment?
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.
Fixed comment
libs/small-steps/src/Data/Sharing.hs
Outdated
-- ======================================= | ||
|
||
data Intern a = Intern | ||
{ internMaybe :: a -> Maybe a, |
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.
Can we add a comment on this function? I guess it's the critical function here
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.
Indeed it could use a comment. I'll add one
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.
I added some haddock, let me know if it makes sense and if it is enough of an explanation
9d9fb15
to
5c04fb4
Compare
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.
Misc typos, otherwise looks good!
47284b8
to
e400ad7
Compare
* Added the Cardano.Ledger.Sharing module * This supports sharing when deserializing. Made changes to share `Credential 'Staking crypto` and `KeyHash 'StakePool crypto` in `EpochState` * Add shring to `NonMyopic` * Benchmark EpochState sharing * Avoid order of arguments with NamedFieldPuns in serialization * Simplify `FromSharedCBOR` by removing `StateT` from `fromSharedCBOR` * Apply sharing to `TxOut`
e400ad7
to
71f6263
Compare
This is an alternative approach to the one implemented in #2548
Applied sharing to all places possible in EpochState, including TxOuts in the UTxO. These are the results we get: