[
https://issues.apache.org/jira/browse/KAFKA-20249?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18064979#comment-18064979
]
Guang Zhao edited comment on KAFKA-20249 at 3/11/26 2:22 AM:
-------------------------------------------------------------
Thanks. I ran a new JMH benchmark comparing existing approach vs the fast path
for zero headers -- the fast path shows about 2x higher throughput on my local
machine:
{code:java}
Benchmark Mode Cnt
Score Error Units
RawBytesExtraction.testRawAggregationWithoutHeaders thrpt 15
7850.891 ± 307.428 ops/s
RawBytesExtraction.testRawAggregationWithoutHeadersFastPath thrpt 15
14957.556 ± 517.450 ops/s
{code}
Looks promising. I will finish up the implementation, and aim to open a PR by
tomorrow :)
was (Author: JIRAUSER308070):
Thanks. I ran a new JMH benchmark comparing existing approach vs the fast path
for zero headers, about 2x higher throughput on my local machine:
{code:java}
Benchmark Mode Cnt
Score Error Units
RawBytesExtraction.testRawAggregationWithoutHeaders thrpt 15
7850.891 ± 307.428 ops/s
RawBytesExtraction.testRawAggregationWithoutHeadersFastPath thrpt 15
14957.556 ± 517.450 ops/s
{code}
Looks promising. I will finish up the implementation, and aim to open a PR by
tomorrow :)
> Optimize rawValue methods across all Deserializers
> --------------------------------------------------
>
> Key: KAFKA-20249
> URL: https://issues.apache.org/jira/browse/KAFKA-20249
> Project: Kafka
> Issue Type: Sub-task
> Components: streams
> Reporter: Alieh Saeedi
> Assignee: Guang Zhao
> Priority: Major
> Labels: kip
> Fix For: 4.3.0
>
>
> Optimize rawValue/{{{}rawAggregationValue{}}} to fast-path the common case of
> empty headers in headers-aware state stores, while preserving correct
> behavior for non-empty headers.
> h3. Background
> In the current header-aware state store encoding, the value layout is:
> * 1st byte: header-length prefix (or start of varint-encoded header size)
> * Next {{N}} bytes: serialized headers
> * Remaining bytes: aggregation value (payload)
> Most state store records are expected to have no headers, so optimizing the
> empty-headers case reduces overhead in hot paths where we need to extract the
> raw aggregation value.
> h3. Proposed Change
> Introduce a specialized implementation of rawValue/{{{}rawAggregationValue.
> {}}}
> ```
> {{// Fast path for empty headers (most common case)}}
> {{ if (valueWithHeaders[0] == 0x00){ }}
> {{ // Headers size is 0, just strip first byte }}
> {{ final byte[] result = new byte[valueWithHeaders.length - 1];
> }}{{
> System.arraycopy(valueWithHeaders, 1, result, 0, result.length);
> }}
> {{ return result; }}
> }
> {{// Slow path for actual headers (rare in session stores)}}
> {{...}}
> ```
> Pros:
> - Optimizes the common case (empty headers)
> - ~50% faster for empty headers (no ByteBuffer, simple arraycopy)
> - Still handles non-empty headers correctly
--
This message was sent by Atlassian Jira
(v8.20.10#820010)