Skip to content

Conversation

@lehins
Copy link
Collaborator

@lehins lehins commented Dec 25, 2025

Description

This PR switches OutputVRF to use ByteArray in order to not contribute to pinned memory fragmentation.
Also it switches decoding of PackedBytes to use ByteString for temporary buffer to avoid unnecessary copy.

Couple of useful FromCBOR/ToCBOR instances were added to accommodate above changes

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • All visible changes are prepended to the latest section of a CHANGELOG.md for the affected packages.
    New section is never added with the code changes. (See RELEASING.md)
  • When applicable, versions are updated in .cabal and CHANGELOG.md files according to the
    versioning process.
  • The version bounds in .cabal files for all affected packages are updated.
    If you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md)
  • Self-reviewed the diff

@lehins lehins requested a review from a team as a code owner December 25, 2025 16:22
@lehins lehins force-pushed the lehins/memory-optimizations branch 2 times, most recently from 6862daa to d72cb08 Compare December 25, 2025 17:04
@lehins lehins requested a review from neilmayhew December 25, 2025 17:44
@lehins lehins force-pushed the lehins/memory-optimizations branch from d72cb08 to 3cac086 Compare December 25, 2025 17:45
`OutputVRF` is small in size and is persisted in memory for some time,
since we keep around block headers for a while. In order to not
contribute to pinned memory fragmentation and not to retain unnecessary
bytes it is better to switch to unpinned `ByteArray` from pinned
`ByteString`
As it turns out `cborg` library whenever decoing `ByteString` it will
take a slice in constant time of the original large buffer that is
being fed to the decoder, while it can't do the same when decoding
`ByteArray#`. Concidering that for `PackedBytes` this intermediate
buffer is short lived, because it is only needed for packing operation,
it totally makes sense to not make a redundant copy of this buffer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants