-
Notifications
You must be signed in to change notification settings - Fork 88
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
Use ShortByteString for OneEraHash and ConvertRawHash #2266
Conversation
86748c6
to
f5950f3
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.
Currently a draft, as we currently require going through a regular ByteString
for both Byron and Shelley (see my inline comments).
If/when we decide to switch to ShortByteString
s, it would be good to measure the actual difference in memory usage.
UPDATE: both Byron's and Shelley's hash type now uses a ShortByteString
under the hood and expose the necessary conversions (avoiding going through an intermediary Strict.ByteString
).
ouroboros-consensus-byron/src/Ouroboros/Consensus/Byron/Ledger/Block.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus-shelley/src/Ouroboros/Consensus/Shelley/Ledger/Block.hs
Outdated
Show resolved
Hide resolved
f5950f3
to
12820e3
Compare
12820e3
to
dea8236
Compare
Since the Byron and Shelley hash types are `ShortByteString`s under the hood, switch over the representation of `OneEraHash` from `Strict.ByteString` to `ShortByteString` too. To avoid the intermediary `Strict.ByteString` in the conversion, add `toShortRawHash` and `fromShortRawHash` to `ConvertRawHash`. This avoids the memory overhead that a regular strict `ByteString` has. According to the [Haddocks of `ShortByteString`][SBS], using a `ByteString` (unshared) for a 32 byte hash (which is the case for Byron and Shelley) requires 72 + 32 bytes, but a `ShortByteString` requires only 32 + 32 bytes. This can make a noticeable difference in memory usage as we're keeping lots of hashes in memory: * O(k) in the in-memory indices of the VolatileDB (hash and prev hash) * O(cached epochs * epoch size) in the secondary index caches of the ImmutableDB * ... [SBS]: http://hackage.haskell.org/package/bytestring-0.10.10.0/docs/Data-ByteString-Short.html#g:2
dea8236
to
458548a
Compare
Glad to have this major performance penalty gone finally 😏 |
bors ping |
pong |
bors merge |
Since the Byron and Shelley hash types are
ShortByteString
s under the hood,switch over the representation of
OneEraHash
fromStrict.ByteString
toShortByteString
too.To avoid the intermediary
Strict.ByteString
in the conversion, addtoShortRawHash
andfromShortRawHash
toConvertRawHash
.This avoids the memory overhead that a regular strict
ByteString
has.According to the Haddocks of
ShortByteString
, using aByteString
(unshared) for a 32 byte hash (which is the case for Byron andShelley) requires 72 + 32 bytes, but a
ShortByteString
requires only 32 + 32bytes. This can make a noticeable difference in memory usage as we're keeping
lots of hashes in memory:
ImmutableDB