Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fingerprint mechanism now calculates Shannon entropy.
- Lading now supports a '--json-logs' flag to output logs in structured JSON
format.
- Resize blocks after payload generation so that when a significant portion of
the buffer is unused it frees that memory.

## [0.30.0]
## Added
Expand Down
11 changes: 10 additions & 1 deletion lading_payload/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,16 @@ where
{
let mut block: Writer<BytesMut> = BytesMut::with_capacity(chunk_size as usize).writer();
serializer.to_bytes(&mut rng, chunk_size as usize, &mut block)?;
let bytes: Bytes = block.into_inner().freeze();
let inner = block.into_inner();
// When the actual block data usage is under half of its allocated capacity (chunk_size),
// shrink its buffer to the actual size to avoid holding onto excess capacity.
// This ensures that generators with lots of small blocks respect the total cache size, and
// no block cache will hold more than 2x the total cache size in allocated buffers.
let bytes: Bytes = if inner.len() < inner.capacity() / 2 {
Bytes::copy_from_slice(&inner)
} else {
inner.freeze()
};
if bytes.is_empty() {
// Blocks should not be empty and if they are empty this is an
// error. Caller may choose to handle this however they wish, often it
Expand Down
Loading