-
Notifications
You must be signed in to change notification settings - Fork 158
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
Validation benchmarks and performance improvements #1785
Conversation
This is an additional set of constraints on the mock crypto for use in examples. Crucially, it is required whenever we rely on using the fake VRF algorithm.
shelley/chain-and-ledger/shelley-spec-ledger-test/shelley-spec-ledger-test.cabal
Outdated
Show resolved
Hide resolved
shelley/chain-and-ledger/shelley-spec-ledger-test/shelley-spec-ledger-test.cabal
Outdated
Show resolved
Hide resolved
@@ -999,6 +999,7 @@ compute:: Exp t -> t | |||
compute (Base rep relation) = relation | |||
|
|||
compute (Dom (Base SetR rel)) = rel | |||
compute (Dom (Base MapR x)) = Sett (Map.keysSet x) |
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 reminds me of #1775, but doesn't help (yet?) because STS.bbodySlots = eval (dom nesOsched)
forces the evaluation when creating the BbodyEnv
: https://github.com/input-output-hk/cardano-ledger-specs/blob/d0f7eded325c4e4b36e44b4b49fd75b0c83f00f3/shelley/chain-and-ledger/executable-spec/src/Shelley/Spec/Ledger/API/Validation.hs#L72
shelley/chain-and-ledger/executable-spec/src/Shelley/Spec/Ledger/DeserializeShort.hs
Outdated
Show resolved
Hide resolved
shelley/chain-and-ledger/executable-spec/shelley-spec-ledger.cabal
Outdated
Show resolved
Hide resolved
addr = case deserialiseAddr (BSS.fromShort bs) of | ||
Nothing -> panic "viewCompactTxOut: impossible" | ||
addr = case deserializeShortAddr bs of -- Try to deserialize a Shelley style Addr directly from ShortByteString | ||
Just (a :: Addr crypto) -> a | ||
Nothing -> case deserialiseAddr (BSS.fromShort bs) of -- It is a Byron Address, try the more expensive route. | ||
Nothing -> panic "viewCompactTxOut: impossible" | ||
Just (a :: Addr crypto) -> 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.
Great! Is the goal to eventually let deserializeShortAddr
support Byron addresses too?
7fc147b
to
646ff9d
Compare
These cover two areas: - Block generation (via 'genBlock') - Block and header application (in 'BenchValidation')
In particular the function 'viewCompactTxOut' which now tries to serialize the Address directly from a ShortByteString, and falls back to the expensive 'deserialiseAddr' only if that fails. Benchmarking shows that it almost always succeeds. This speeds up the 'applyBlockTransition' function about 10-12%. More speedup is possible because the new bottle neck is the function 'substring :: ShortByteString -> Int -> Int -> ShortByteString' which has an absolutely horrible implementation, it should use a single allocation and a memcopy operation, but instead it goes through 2 intermediate lists.
Work by Tim Sheard.
646ff9d
to
bcadc46
Compare
In my microbenchmark, this brings down the cost of deserialising a Shelley address in `viewCompactTxOut` from ~360ns to ~60ns. The `cloneByteArray` function was introduced in version 0.7.1.0 of the `primitive` package, so update the lower bound accordingly. I believe the old `primitive < 0.7` constraint in `cabal.project` was due to older versions of the `cborg` package having `>=0.5 && <0.7.1.0` as bounds for `primitive`, but `cborg-0.2.4.0` bumped the upper bound to 0.8. This will likely require similar changes to downstream repos.
The dependency on cborg was pinned to an unreleased revision to bring in <well-typed/cborg#223>. That PR has been included in the cborg 0.2.3.0, so we remove the dependency pin in favour of bumping the lower bound on the version. Instead of using 0.2.3 as the lower bound, bump it to 0.2.4, as this version is compatible with the last version of the `primitive` package, which will soon be needed by `cardano-ledger-specs`, see <IntersectMBO/cardano-ledger#1785>. Another advantage of using a released version is that the package will now be stored in the global cabal store and shared between projects (although that will also be the case for source dependencies in Cabal 3.4.0.0).
The dependency on cborg was pinned to an unreleased revision to bring in <well-typed/cborg#223>. That PR has been included in `cborg-0.2.3.0`, so we can remove the dependency pin in favour of bumping the lower version bound on the dependency. Instead of using 0.2.3 as the lower version bound, bump it to >= 0.2.4, as this version is compatible with the last version of the `primitive` package, which will soon be needed by `cardano-ledger-specs`, see <IntersectMBO/cardano-ledger#1785>. Another advantage of using a released version is that the package will now be stored in the global cabal store and shared between projects (although that will also be the case for source dependencies in Cabal 3.4.0.0).
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.
LGTM!
The dependency on cborg was pinned to an unreleased revision to bring in <well-typed/cborg#223>. That PR has been included in `cborg-0.2.3.0`, so we can remove the dependency pin in favour of bumping the lower version bound on the dependency. Instead of using 0.2.3 as the lower version bound, bump it to >= 0.2.4, as this version is compatible with the last version of the `primitive` package, which will soon be needed by `cardano-ledger-specs`, see <IntersectMBO/cardano-ledger#1785>. Another advantage of using a released version is that the package will now be stored in the global cabal store and shared between projects (although that will also be the case for source dependencies in Cabal 3.4.0.0).
The dependency on cborg was pinned to an unreleased revision to bring in <well-typed/cborg#223>. That PR has been included in `cborg-0.2.3.0`, so we can remove the dependency pin in favour of bumping the lower version bound on the dependency. Instead of using 0.2.3 as the lower version bound, bump it to >= 0.2.4, as this version is compatible with the last version of the `primitive` package, which will soon be needed by `cardano-ledger-specs`, see <IntersectMBO/cardano-ledger#1785>. Another advantage of using a released version is that the package will now be stored in the global cabal store and shared between projects (although that will also be the case for source dependencies in Cabal 3.4.0.0).
FYI, using this branch + #1775, I get the following profiling hotspots when running consensus'
My takeaway from this: there is no obvious nail we can hammer on. The two first entries are C functions. We can check whether I'm thinking about parallelising/pipelining header vs. block validation or batching it. Pipeling and batching would require a major redesign, as validation (header + block) is inherently sequential. Parallelising header and block validation is easier, but it would be limited to validating a single block's header in parallel to the validation of the block/body, so there's less to win. Note that that code is pure at the moment, we could keep it pure by using |
Highlights: * IntersectMBO/cardano-ledger#1784 * IntersectMBO/cardano-ledger#1785 * IntersectMBO/cardano-ledger#1779 * IntersectMBO/ouroboros-network#2512 * Remove unused source-repository-package cardano-sl-x509 (this package required the `ip < 1.5` constraint which conflicted with the `primitive >= 0.7.1.0` lower bound in `cardano-ledger-specs`). * Remove unused http-client dependency from stack.yaml * Remove duplicate from cabal.project
The dependency on cborg was pinned to an unreleased revision to bring in <well-typed/cborg#223>. That PR has been included in `cborg-0.2.3.0`, so we can remove the dependency pin in favour of bumping the lower version bound on the dependency. Instead of using 0.2.3 as the lower version bound, bump it to >= 0.2.4, as this version is compatible with the last version of the `primitive` package, which will soon be needed by `cardano-ledger-specs`, see <IntersectMBO/cardano-ledger#1785>. Another advantage of using a released version is that the package will now be stored in the global cabal store and shared between projects (although that will also be the case for source dependencies in Cabal 3.4.0.0).
The dependency on cborg was pinned to an unreleased revision to bring in <well-typed/cborg#223>. That PR has been included in `cborg-0.2.3.0`, so we can remove the dependency pin in favour of bumping the lower version bound on the dependency. Instead of using 0.2.3 as the lower version bound, bump it to >= 0.2.4, as this version is compatible with the last version of the `primitive` package, which will soon be needed by `cardano-ledger-specs`, see <IntersectMBO/cardano-ledger#1785>. Another advantage of using a released version is that the package will now be stored in the global cabal store and shared between projects (although that will also be the case for source dependencies in Cabal 3.4.0.0).
Highlights: * IntersectMBO/cardano-ledger#1784 * IntersectMBO/cardano-ledger#1785 * IntersectMBO/cardano-ledger#1779 * IntersectMBO/cardano-ledger#1785 * IntersectMBO/cardano-ledger#1742 * IntersectMBO/ouroboros-network#2512 * Remove unused source-repository-package cardano-sl-x509 (this package required the `ip < 1.5` constraint which conflicted with the `primitive >= 0.7.1.0` lower bound in `cardano-ledger-specs`). * Remove unused http-client dependency from stack.yaml * Remove duplicate from cabal.project
1696: Update dependencies r=mrBliss a=mrBliss Highlights: * IntersectMBO/cardano-ledger#1784 * IntersectMBO/cardano-ledger#1785 * IntersectMBO/cardano-ledger#1779 * IntersectMBO/cardano-ledger#1785 * IntersectMBO/cardano-ledger#1742 * IntersectMBO/ouroboros-network#2512 Co-authored-by: Thomas Winant <thomas@well-typed.com> Co-authored-by: Samuel Leathers <samuel.leathers@iohk.io>
I aggree with your analysis. Everything that does a lookup in one of the ledger states Maps or Sets goes through 'compute' if that only uses 2% of the time, it is unlikely that could be improved enough to make a difference. |
The dependency on cborg was pinned to an unreleased revision to bring in <well-typed/cborg#223>. That PR has been included in `cborg-0.2.3.0`, so we can remove the dependency pin in favour of bumping the lower version bound on the dependency. Instead of using 0.2.3 as the lower version bound, bump it to >= 0.2.4, as this version is compatible with the last version of the `primitive` package, which will soon be needed by `cardano-ledger-specs`, see <IntersectMBO/cardano-ledger#1785>. Another advantage of using a released version is that the package will now be stored in the global cabal store and shared between projects (although that will also be the case for source dependencies in Cabal 3.4.0.0).
The dependency on cborg was pinned to an unreleased revision to bring in <well-typed/cborg#223>. That PR has been included in `cborg-0.2.3.0`, so we can remove the dependency pin in favour of bumping the lower version bound on the dependency. Instead of using 0.2.3 as the lower version bound, bump it to >= 0.2.4, as this version is compatible with the last version of the `primitive` package, which will soon be needed by `cardano-ledger-specs`, see <IntersectMBO/cardano-ledger#1785>. Another advantage of using a released version is that the package will now be stored in the global cabal store and shared between projects (although that will also be the case for source dependencies in Cabal 3.4.0.0).
1696: Update dependencies r=mrBliss a=mrBliss Highlights: * IntersectMBO/cardano-ledger#1784 * IntersectMBO/cardano-ledger#1785 * IntersectMBO/cardano-ledger#1779 * IntersectMBO/cardano-ledger#1785 * IntersectMBO/cardano-ledger#1742 * IntersectMBO/ouroboros-network#2512 Co-authored-by: Thomas Winant <thomas@well-typed.com> Co-authored-by: Samuel Leathers <samuel.leathers@iohk.io>
This is a cleaned and rebased version of #1767.
It may be reviewed commit by commit. Particular attention should be paid in review to the
TxOut
pattern changes.Much of the work here is due to @TimSheard, I've just tidied it up for review.