Skip to content

feat: add simd add/sub/mul expressions#19512

Open
clintropolis wants to merge 3 commits into
apache:masterfrom
clintropolis:expression-vector-api
Open

feat: add simd add/sub/mul expressions#19512
clintropolis wants to merge 3 commits into
apache:masterfrom
clintropolis:expression-vector-api

Conversation

@clintropolis
Copy link
Copy Markdown
Member

@clintropolis clintropolis commented May 25, 2026

Description

This PR adds a new config druid.expressions.useVectorApi to allow using the incubating JDK Vector API ((also requires running Druid with flags --add-modules jdk.incubator.vector).

The measurements look pretty nice, though I think perhaps some of the simpler expressions I measured might have already been eligible for auto-vectorization given that the numbers look approximately the same for the first few:

Benchmark                        (complexCompression)  (deferExpressionDimensions)  (jsonObjectStorageEncoding)  (query)  (rowsPerSegment)  (schemaType)  (storageType)  (stringEncoding)  (useVectorApi)  (vectorize)  Mode  Cnt   Score   Error  Units
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE        7           1500000      explicit           MMAP              UTF8           false        force  avgt    5  14.404 ± 0.699  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE        7           1500000      explicit           MMAP              UTF8            true        force  avgt    5  14.647 ± 0.866  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE        8           1500000      explicit           MMAP              UTF8           false        force  avgt    5  24.437 ± 0.973  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE        8           1500000      explicit           MMAP              UTF8            true        force  avgt    5  24.367 ± 1.530  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE        9           1500000      explicit           MMAP              UTF8           false        force  avgt    5  26.923 ± 0.841  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE        9           1500000      explicit           MMAP              UTF8            true        force  avgt    5  26.668 ± 1.180  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       10           1500000      explicit           MMAP              UTF8           false        force  avgt    5  43.108 ± 2.033  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       10           1500000      explicit           MMAP              UTF8            true        force  avgt    5  38.607 ± 0.690  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       11           1500000      explicit           MMAP              UTF8           false        force  avgt    5  61.805 ± 0.641  ms/op
SqlExpressionBenchmark.querySql                  NONE                 singleString                        SMILE       11           1500000      explicit           MMAP              UTF8            true        force  avgt    5  35.907 ± 0.516  ms/op

I just did add/subtract/multiply implmenetations so far, but there are a few other easy wins that I'll probably add over a few follow-up PRs.

Copy link
Copy Markdown
Member

@FrankChen021 FrankChen021 left a comment

Choose a reason for hiding this comment

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

I have reviewed the code for correctness, edge cases, concurrency, and integration risks; no issues found.

Reviewed 30 of 30 changed files.


This is an automated review by Codex GPT-5.5

@Shekharrajak
Copy link
Copy Markdown
Contributor

This is looking nice, I would like to know any discussion around using JDK based SIMD or native Rust/Cpp based SIMD to understand the improvements, benefits we will get and tradeoff.

Ref #19456

@FrankChen021
Copy link
Copy Markdown
Member

This is looking nice, I would like to know any discussion around using JDK based SIMD or native Rust/Cpp based SIMD to understand the improvements, benefits we will get and tradeoff.

Ref #19456

I think starting from Vector API is a natural first step.
If there are some sophisticated Rust/Cpp based SIMD libs (already wide used by Java apps) that have significant improvement over vector API, it's worth trying.

@clintropolis
Copy link
Copy Markdown
Member Author

This is looking nice, I would like to know any discussion around using JDK based SIMD or native Rust/Cpp based SIMD to understand the improvements, benefits we will get and tradeoff.

Ref #19456

I guess I view this change and my planned follow-ups as sort of orthogonal to whatever experiments are done re #19456; that said these changes do make a baseline of what our current stuff can do which we can measure any experiments against.

@jtuglu1
Copy link
Copy Markdown
Contributor

jtuglu1 commented May 28, 2026

I suspect benchmarks will look better on the JDK 25 compiler (next release).

{
for (int iterations = 0; iterations < numIterations; iterations++) {
assertEvalsMatch(expr, parsed, makeRandomizedBindings(VECTOR_SIZE, types));
for (int vectorSize : VECTOR_SIZES) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a VectorExprResultConsistencyTest for one side or the other being 100% null? Would be a good case to check for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants