Skip to content

Multiple optimizations of vector copies, spans, and Snappy API raw compression#222

Merged
avalerio-tkd merged 2 commits intomainfrom
av_buffers_optimizing_encrypt_043
Mar 4, 2026
Merged

Multiple optimizations of vector copies, spans, and Snappy API raw compression#222
avalerio-tkd merged 2 commits intomainfrom
av_buffers_optimizing_encrypt_043

Conversation

@avalerio-tkd
Copy link
Collaborator

  • Multiple optimizations to switch to using tcb::span instead of std::vector.
  • Removed unnecessary copied returns of std::vector values.
  • Swtiched to the more performant Snappy raw API for compression.

…:vector.

- Removed unnecessary copied returns of std::vector values.
- Swtiched to the more performant Snappy raw API for compression.
Copy link
Collaborator

@argmarco-tkd argmarco-tkd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Overall LGTM. Left a few questions, none of which are blockers if they are not redflags/concerns for you. Approving.

snappy::Compress(reinterpret_cast<const char*>(bytes.data()), bytes.size(), &compressed);
return std::vector<uint8_t>(compressed.begin(), compressed.end());
std::vector<uint8_t> out_buffer;
out_buffer.resize(snappy::MaxCompressedLength(bytes.size()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just how large can this get? (IOW - is there a risk of this causing some OOM because the estimated compressed length too large?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, this is the MaxCompressedLength for the particular byte array, not an absolute max. The heuristic for the size.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - the question was more around how 'accurate' the heuristic was. Also checked. The operation is very quick, and the heuristic is fairly decent. All good.

https://github.com/google/snappy/blob/main/snappy.cc#L197-L219

Copy link
Collaborator Author

@avalerio-tkd avalerio-tkd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the comments @argmarco-tkd , specially the dedup'd of Split. Merging.

snappy::Compress(reinterpret_cast<const char*>(bytes.data()), bytes.size(), &compressed);
return std::vector<uint8_t>(compressed.begin(), compressed.end());
std::vector<uint8_t> out_buffer;
out_buffer.resize(snappy::MaxCompressedLength(bytes.size()));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, this is the MaxCompressedLength for the particular byte array, not an absolute max. The heuristic for the size.

@avalerio-tkd avalerio-tkd merged commit bb46804 into main Mar 4, 2026
2 checks passed
@avalerio-tkd avalerio-tkd deleted the av_buffers_optimizing_encrypt_043 branch March 4, 2026 18:13
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