File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717- Fingerprint mechanism now calculates Shannon entropy.
1818- Lading now supports a '--json-logs' flag to output logs in structured JSON
1919 format.
20+ - Resize blocks after payload generation so that when a significant portion of
21+ the buffer is unused it frees that memory.
2022
2123## [ 0.30.0]
2224## Added
Original file line number Diff line number Diff line change @@ -675,7 +675,16 @@ where
675675{
676676 let mut block: Writer < BytesMut > = BytesMut :: with_capacity ( chunk_size as usize ) . writer ( ) ;
677677 serializer. to_bytes ( & mut rng, chunk_size as usize , & mut block) ?;
678- let bytes: Bytes = block. into_inner ( ) . freeze ( ) ;
678+ let inner = block. into_inner ( ) ;
679+ // When the actual block data usage is under half of its allocated capacity (chunk_size),
680+ // shrink its buffer to the actual size to avoid holding onto excess capacity.
681+ // This ensures that generators with lots of small blocks respect the total cache size, and
682+ // no block cache will hold more than 2x the total cache size in allocated buffers.
683+ let bytes: Bytes = if inner. len ( ) < inner. capacity ( ) / 2 {
684+ Bytes :: copy_from_slice ( & inner)
685+ } else {
686+ inner. freeze ( )
687+ } ;
679688 if bytes. is_empty ( ) {
680689 // Blocks should not be empty and if they are empty this is an
681690 // error. Caller may choose to handle this however they wish, often it
You can’t perform that action at this time.
0 commit comments