You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "stevenschlansker (via GitHub)" <gi...@apache.org> on 2025/12/03 23:21:47 UTC
[PR] MINOR: Bytes lexicographic comparator could use compiler builtin [kafka]
stevenschlansker opened a new pull request, #21073:
URL: https://github.com/apache/kafka/pull/21073
The `Arrays.compare` method has a vectorized compiler intrinsic available and should offer better performance than a hand-rolled loop.
The JDK implementation is at least able to compare 8 bytes at a time instead of 1 byte at a time, and avoids repeated bounds-checking.
This operation is performance-sensitive if you use in-memory stores, since it is used to navigate the TreeMap backing the store.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Bytes lexicographic comparator could use compiler builtin [kafka]
Posted by "bbejeck (via GitHub)" <gi...@apache.org>.
bbejeck merged PR #21073:
URL: https://github.com/apache/kafka/pull/21073
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Bytes lexicographic comparator could use compiler builtin [kafka]
Posted by "bbejeck (via GitHub)" <gi...@apache.org>.
bbejeck commented on PR #21073:
URL: https://github.com/apache/kafka/pull/21073#issuecomment-3620553376
@stevenschlansker nice improvement! Could you rebase and also add a JMH benchmark for this in the `jmh-benchmarks` module? Not strictly necessary, but it's always good to have one for these types of PRs to demonstrate the improvement.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Bytes lexicographic comparator could use compiler builtin [kafka]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #21073:
URL: https://github.com/apache/kafka/pull/21073#issuecomment-3639923429
A label of 'needs-attention' was automatically added to this PR in order to raise the
attention of the committers. Once this issue has been triaged, the `triage` label
should be removed to prevent this automation from happening again.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Bytes lexicographic comparator could use compiler builtin [kafka]
Posted by "squah-confluent (via GitHub)" <gi...@apache.org>.
squah-confluent commented on PR #21073:
URL: https://github.com/apache/kafka/pull/21073#issuecomment-3638541838
It's not too bad. We just need a single parameterized test taking `(s1, s2, expectedSign)` and run a list of inputs through `compare()`. These ought to be sufficient:
```java
// Empty strings
"", "", 0
"", "aaa", -1
"aaa", "", 1
"aaa", "aaa", 0
"aaa", "bbb", -1
"bbb", "aaa", 1
// Same as above, but with different lengths (can probably skip this)
"aaaaaa", "bbb", -1
"aaa", "bbbbbb", -1
"bbbbbb", "aaa", 1
"bbb", "aaaaaa", 1
// Strings have a common prefix
"common_prefix_aaa", "common_prefix_bbb", -1
"common_prefix_bbb", "common_prefix_aaa", 1
// Same as above, but with different lengths (can probably skip this)
"common_prefix_aaaaaa", "common_prefix_bbb", -1
"common_prefix_aaa", "common_prefix_bbbbbb", -1
"common_prefix_bbbbbb", "common_prefix_aaa", 1
"common_prefix_bbb", "common_prefix_aaaaaa", 1
// One string is a prefix of the other
"common_prefix", "common_prefix_aaa", -1
"common_prefix_aaa", "common_prefix", 1
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Bytes lexicographic comparator could use compiler builtin [kafka]
Posted by "stevenschlansker (via GitHub)" <gi...@apache.org>.
stevenschlansker commented on PR #21073:
URL: https://github.com/apache/kafka/pull/21073#issuecomment-3617719802
The test failures seem to be intermittent and unrelated to my change...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Bytes lexicographic comparator could use compiler builtin [kafka]
Posted by "stevenschlansker (via GitHub)" <gi...@apache.org>.
stevenschlansker commented on PR #21073:
URL: https://github.com/apache/kafka/pull/21073#issuecomment-3639580609
Ok I added the requested test cases
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Bytes lexicographic comparator could use compiler builtin [kafka]
Posted by "stevenschlansker (via GitHub)" <gi...@apache.org>.
stevenschlansker commented on PR #21073:
URL: https://github.com/apache/kafka/pull/21073#issuecomment-3647657024
The benchmark now has both versions side by side
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Bytes lexicographic comparator could use compiler builtin [kafka]
Posted by "bbejeck (via GitHub)" <gi...@apache.org>.
bbejeck commented on PR #21073:
URL: https://github.com/apache/kafka/pull/21073#issuecomment-3648055317
Merged #21073 into trunk
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Bytes lexicographic comparator could use compiler builtin [kafka]
Posted by "squah-confluent (via GitHub)" <gi...@apache.org>.
squah-confluent commented on PR #21073:
URL: https://github.com/apache/kafka/pull/21073#issuecomment-3646891854
> @squah-confluent did you want to take another look?
I'm happy with the test. @stevenschlansker thanks for adding test coverage.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Bytes lexicographic comparator could use compiler builtin [kafka]
Posted by "squah-confluent (via GitHub)" <gi...@apache.org>.
squah-confluent commented on PR #21073:
URL: https://github.com/apache/kafka/pull/21073#issuecomment-3619726611
The test failures were my fault. They're fixed now.
Really nice improvement! I notice we are missing test coverage for the comparator. The change looks correct but it would be nice to test we aren't changing behavior in any edge cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Bytes lexicographic comparator could use compiler builtin [kafka]
Posted by "stevenschlansker (via GitHub)" <gi...@apache.org>.
stevenschlansker commented on PR #21073:
URL: https://github.com/apache/kafka/pull/21073#issuecomment-3635331075
I added a simple benchmark comparing TreeMap lookups with keys having shared prefixes of various lengths.
```
before
Benchmark (bytes) Mode Cnt Score Error Units
BytesCompareBenchmark.samePrefixLexico 8 thrpt 20 1.628 ± 0.027 ops/ms
BytesCompareBenchmark.samePrefixLexico 16 thrpt 20 1.187 ± 0.008 ops/ms
BytesCompareBenchmark.samePrefixLexico 32 thrpt 20 0.856 ± 0.007 ops/ms
BytesCompareBenchmark.samePrefixLexico 128 thrpt 20 0.313 ± 0.001 ops/ms
BytesCompareBenchmark.samePrefixLexico 1024 thrpt 20 0.042 ± 0.001 ops/ms
after:
Benchmark (bytes) Mode Cnt Score Error Units
BytesCompareBenchmark.samePrefixLexico 8 thrpt 20 2.272 ± 0.061 ops/ms
BytesCompareBenchmark.samePrefixLexico 16 thrpt 20 1.622 ± 0.022 ops/ms
BytesCompareBenchmark.samePrefixLexico 32 thrpt 20 1.501 ± 0.008 ops/ms
BytesCompareBenchmark.samePrefixLexico 128 thrpt 20 0.970 ± 0.004 ops/ms
BytesCompareBenchmark.samePrefixLexico 1024 thrpt 20 0.304 ± 0.001 ops/ms
```
So it looks like at least on my M3 Mac, using the compiler intrinsic is better across the board - about 30% better for short values and almost 8x faster for very long equal runs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Bytes lexicographic comparator could use compiler builtin [kafka]
Posted by "stevenschlansker (via GitHub)" <gi...@apache.org>.
stevenschlansker commented on PR #21073:
URL: https://github.com/apache/kafka/pull/21073#issuecomment-3638001812
On a temporary branch, I modified the comparator to run both algorithms and `assert` they return the same result. With this, the unit tests continue to pass. That's not necessarily a replacement for extensive testing for edge cases, but I'm also not really volunteering to write such a volume of tests, unless there's a short specific list :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org