Skip to content

Conversation

@iverase
Copy link
Contributor

@iverase iverase commented Aug 13, 2025

Speed up BQSpaceUtils#transposeHalfByte by unrolly the elements of the array 8 at a time and manually packing the bits. The code is a bit less readable but twice at fast:

Benchmark                                           (dims)   Mode  Cnt  Score   Error   Units
TransposeHalfByteBenchmark.transposeHalfByte           384  thrpt    5  3.356 ± 0.499  ops/ms
TransposeHalfByteBenchmark.transposeHalfByte           782  thrpt    5  1.657 ± 0.014  ops/ms
TransposeHalfByteBenchmark.transposeHalfByte          1024  thrpt    5  1.304 ± 0.021  ops/ms
TransposeHalfByteBenchmark.transposeHalfByteLegacy     384  thrpt    5  1.719 ± 0.049  ops/ms
TransposeHalfByteBenchmark.transposeHalfByteLegacy     782  thrpt    5  0.835 ± 0.005  ops/ms
TransposeHalfByteBenchmark.transposeHalfByteLegacy    1024  thrpt    5  0.652 ± 0.002  ops/ms

It should hint a patch forward for vectorization (if this is not already auto-vectorize which I haven't checked).

relates #132761

@iverase iverase requested a review from benwtrent August 13, 2025 08:46
@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Aug 13, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

Copy link
Member

@benwtrent benwtrent left a comment

Choose a reason for hiding this comment

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

yeah, its an eye-sore.

There must be a faster way (so many of the bit shifts are fairly uniform, making me think they could be done in a single action...oh well).

Progress over perfection :). 2x faster is nice

@iverase iverase merged commit 92d4d6a into elastic:main Aug 13, 2025
33 checks passed
@iverase iverase deleted the transposeHalfByteScalar branch August 13, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :Search Relevance/Vectors Vector search Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants