Skip to content

Conversation

marcin-krystianc
Copy link

@marcin-krystianc marcin-krystianc commented Jul 8, 2025

This patch introduces experimental allocation-free APIs to enhance performance for message consumption and production.

Key API changes include:

  • Consumer API:

    • A new IConsumer<TKey, TValue>.ConsumeWithCallback method allows for allocation-free message consumption by providing a MessageReader struct to a callback. This eliminates heap allocations associated with ConsumeResult for performance-critical scenarios.
  • Producer API:

    • A new IProducer<TKey, TValue>.Produce overload accepts ReadOnlySpan<byte> for message key and value, enabling allocation-free message production.
    • A new ProducerBuilder<TKey, TValue>.SetAllocFreeDeliveryHandler method allows configuring an AllocFreeDeliveryHandler that receives delivery reports via a MessageReader struct, avoiding allocations for these reports.

Performance

Besides eliminating memory allocations, the new API also eliminates almost the entire managed code overhead. The performance of the new API matches bare C performance. This means that the new API is about 50-100% better than the official API.

@marcin-krystianc marcin-krystianc changed the base branch from master to 2.10.0-gr-experimental July 8, 2025 09:03
@marcin-krystianc marcin-krystianc marked this pull request as draft July 8, 2025 10:10

# Different packaging for tagged vs untagged builds
if ($env:GITHUB_REF -match '^refs/tags/') {
$suffix = "gr-experimental"
Copy link
Author

Choose a reason for hiding this comment

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

gr-experimental suffix

rd_kafka_message* msg)
{
this.msg = msg;
_hdrsPtr = new Lazy<IntPtr>(() =>
Copy link
Author

Choose a reason for hiding this comment

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

I just realised that this is not alloc-free. Will update it.

@marcin-krystianc marcin-krystianc deleted the dev-2.10.0-gr-experimental branch July 8, 2025 13:49
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.

1 participant