Pool internal objects allocated per message #1385
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a followup to #1373 to further reduce objects allocated per message. It takes some inspiration from #1161 but starts with internal allocations, to not require clients to release any objects.
Tested allocations by consuming 2 million (small, ~32 bytes) messages and profiling which functions allocated the most. Here is the base case:
newCRC32Field
is entirely internal, so pooling should be pretty easy here. Let's give that a try.In this case, we see ~24% reduction in allocations (from ~5 allocations per message to ~4). This is about what was expected. Digging further into the implementation, it seems that
lengthField
is equally easy to pool.This shows another ~25.5% reduction in allocated objects, down to ~3 allocations per consumed message. For, the newer format (
RecordBatch
et. al.) the numbers are similar:base (~7 allocations per message):
pool Crc32 (~6 allocations per message):