Skip to content

fix(#10072): a native image uses scalar vector math instead of the uncompiled Vector API - #10077

Merged
robfrank merged 2 commits into
mainfrom
fix/10072-native-image-vector-api-scalar-fallback
Oct 15, 2026
Merged

robfrank merged 2 commits into
mainfrom
fix/10072-native-image-vector-api-scalar-fallback

Conversation

@robfrank

@robfrank robfrank commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #10072

Problem

A GraalVM native image does not compile jdk.incubator.vector calls into SIMD instructions. Each call runs the incubator's pure-Java lane loops, which are several times slower than plain scalar code. jvector still picked PanamaVectorizationProvider in the native binary:

INFO  [VectorizationProvider] Java incubating Vector API enabled. Using PanamaVectorizationProvider.

Measured on macOS aarch64, 20k vectors x 384 dims, COSINE, vector.neighbors k=10:

Server Provider First query (graph build) neighbors median / p90
native Panama (auto) 178.3 s 13.7 / 15.5 ms
native -Djvector.vectorization_provider=default 6.5 s 7.2 / 9.8 ms
JVM 25.0.2 Panama (auto) 3.5 s 6.0 / 7.2 ms

Fix

  • New VectorApiSupport (engine utility): detects a native image through org.graalvm.nativeimage.imagecode, and decides whether jvector must be forced to its scalar provider.
  • LocalDatabase's static initializer calls VectorApiSupport.configureJVectorProvider(). jvector resolves its provider once per process, on first use, and every vector index and vector function needs a LocalDatabase first, so the property is set before jvector reads it. An explicit -Djvector.vectorization_provider=... still wins.
  • GraphOlapVectorOpsProvider and TimeSeriesVectorOpsProvider now choose through a select(boolean) method and use their scalar ops in a native image. On a JVM the selection is unchanged.

Completeness

Invariant: in a native image, no ArcadeDB code path runs the Vector API.

$ git grep -n "VectorizationProvider\|jdk.incubator.vector" -- '*/src/main/java/*.java'
Entry point Status
jvector (LSMVectorIndex, ArcadePageVectorValues, VectorUtils, SQLFunctionVectorAvg, JVectorUtils, jvector internals) fixed: provider forced to default before first resolution
SimdGraphOlapVectorOps via GraphOlapVectorOpsProvider fixed: scalar ops in a native image
SimdTimeSeriesVectorOps via TimeSeriesVectorOpsProvider fixed: scalar ops in a native image (the SIMD warm-up thread no longer starts there either)

Tests

  • VectorApiSupportTest (new, 4 tests): native without a choice -> default; an explicit provider wins; the JVM keeps jvector's own choice; the test JVM is not detected as native.
  • GraphOlapVectorOpsTest / TimeSeriesVectorOpsTest: select(false) returns the scalar ops, select(true) the SIMD ops.
  • Engine vector, sparse/dense vector functions, time-series and Graph-OLAP suites (394 classes, 2807 tests, benchmark and slow excluded): 2806 pass. The one failure, Issue9621SealedStoreChannelReopenTest.readersInterruptedMidScanAllGetTheirRows (ClosedChannelException from an interrupted reader), is a known flake unrelated to this change, and passed 5/5 when run alone.

Residual risk

  • End-to-end native check: passed. A native image built from this branch, started without -Djvector.vectorization_provider, builds the 20k-vector graph in 5.7 s (was 178.3 s) and answers neighbors in 3.6 ms median (was 13.7 ms). Details in the PR comments.
  • Native ingestion stays about 2.5x slower than the JVM with either provider (Serial GC only in GraalVM CE, no JIT profiling). That is general native overhead, out of scope here.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility across runtime environments by selecting SIMD acceleration only when it is available and working correctly.
    • Vector operations now use standard processing when SIMD support is unavailable or fails validation, helping prevent startup or runtime failures.
    • Improved compatibility of vector-based operations in native-image environments while preserving user-configured provider choices where applicable.

…compiled Vector API

A GraalVM native image does not compile jdk.incubator.vector calls into SIMD
instructions: each call runs the incubator's pure-Java lane loops, several
times slower than plain scalar code. jvector still picked its
PanamaVectorizationProvider there, so the graph build of 20k 384-dimension
vectors took 178 s instead of 6.5 s.

VectorApiSupport detects a native image. LocalDatabase's class init points
jvector at its scalar provider before any jvector class resolves one, unless
the user set jvector.vectorization_provider. The Graph-OLAP and time-series
SIMD providers pick their scalar ops in a native image too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robfrank robfrank added this to the 26.11.1 milestone Oct 15, 2026
@robfrank robfrank added performance native-image GraalVM native image vector Vector index and embedding search labels Oct 15, 2026
@robfrank robfrank self-assigned this Oct 15, 2026
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fa8287a3-8b00-4e70-abe8-060c3fcee8ab
📥 Commits

Reviewing files that changed from the base of the PR and between ef9571c and bc21089.

📒 Files selected for processing: 7
  • engine/src/main/java/com/arcadedb/function/sql/vector/SQLFunctionVectorAvg.java
  • engine/src/main/java/com/arcadedb/index/vector/ArcadePageVectorValues.java
  • engine/src/main/java/com/arcadedb/index/vector/LSMVectorIndex.java
  • engine/src/main/java/com/arcadedb/index/vector/VectorUtils.java
  • engine/src/main/java/com/arcadedb/utility/VectorApiSupport.java
  • engine/src/main/java/io/github/jbellis/jvector/vector/JVectorUtils.java
  • engine/src/test/java/com/arcadedb/utility/VectorApiSupportTest.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📝 Walkthrough

VectorApiSupport detects native-image execution and configures jvector before provider resolution. Jvector call sites use that provider. Graph and time-series providers use Vector API compilation status to select scalar or SIMD operations.

Changes: Native-image vector selection

Layer / File(s) Summary
Native-image detection and jvector configuration
engine/src/main/java/com/arcadedb/utility/VectorApiSupport.java, engine/src/main/java/com/arcadedb/database/LocalDatabase.java, engine/src/test/java/com/arcadedb/utility/VectorApiSupportTest.java
VectorApiSupport detects native-image execution and sets jvector’s default provider only when the provider property is absent or blank. LocalDatabase configures jvector before provider resolution. Tests cover configuration and provider access.
jvector provider access across vector operations
engine/src/main/java/com/arcadedb/function/sql/vector/SQLFunctionVectorAvg.java, engine/src/main/java/com/arcadedb/index/vector/*, engine/src/main/java/com/arcadedb/index/vector/VectorUtils.java, engine/src/main/java/io/github/jbellis/jvector/vector/JVectorUtils.java
Vector averaging, vector index access, vector utility operations, and JVectorUtils obtain jvector’s provider through VectorApiSupport. Existing fallbacks and vector creation calls remain in place.
Graph and time-series implementation selection
engine/src/main/java/com/arcadedb/graph/olap/simd/GraphOlapVectorOpsProvider.java, engine/src/main/java/com/arcadedb/engine/timeseries/simd/TimeSeriesVectorOpsProvider.java, engine/src/test/java/com/arcadedb/graph/olap/simd/GraphOlapVectorOpsTest.java, engine/src/test/java/com/arcadedb/engine/timeseries/simd/TimeSeriesVectorOpsTest.java
Both providers select scalar operations when Vector API calls are not compiled to SIMD instructions. Otherwise, they validate SIMD operations and retain scalar fallback behavior. Tests cover both selections.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: lvca

Merge Risk: ⚪ Minimal · up to bc210

Native images will use jvector's scalar provider by default, and JVM behavior and explicit provider settings are unchanged. No concrete merge-blocking issue was identified. The one open item is a native-image benchmark without the provider flag, which the author says has not been run yet.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 31.03% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 11 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed The changes satisfy the coding requirements in [#10072]. VectorApiSupport detects native-image execution and sets jvector to default when no non-blank provider is configured. jvectorProvider() c…
Out of Scope Changes check Passed The reviewed changes stay within [#10072]. They update jvector provider selection, native-image SIMD selection, related call sites, and focused tests. The changes do not address the excluded general n…
Title check Passed The title clearly identifies the main change: native images use scalar vector math instead of the uncompiled Vector API. It is specific, concise, and related to the changeset.
Description check Passed The description explains the problem, motivation, implementation, related issue, testing, performance results, and residual risk. It does not use the template headings and omits the checklist items, b…
Full details: Docstring Coverage

Explanation

Docstring coverage is 31.03% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 11 files. (1 skipped: 1 too large.)

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mergify

mergify Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@claude

claude Bot commented Oct 15, 2026

Copy link
Copy Markdown

Review

Focused fix with a clear measurement table. The select(boolean) seam keeps the providers testable, and the JVM path is unchanged. Notes, most important first.

1. Native-image init timing (main risk, already listed as pending)

  • isNativeImage() is true for both buildtime and runtime values of org.graalvm.nativeimage.imagecode.
  • If LocalDatabase or the two providers are initialized at image build time (--initialize-at-build-time or a native-image.properties entry), the static block runs in the builder JVM. System.setProperty there does not persist into the binary.
  • jvector could also resolve VectorizationProvider before LocalDatabase initializes, so the hook would never take effect.
  • Please check how these classes are initialized in the native-image config, and post the native benchmark without -D before merging. Setting the property from the native entry point or the build args would be a safer extra.

2. Ordering assumption

  • "Every vector index and function needs a LocalDatabase first" holds in the engine today. Callers that touch jvector classes directly (JVectorUtils, VectorUtils, other modules, embedded users) before opening a database bypass the hook.
  • Consider also calling VectorApiSupport.configureJVectorProvider() from the static initializers of the jvector-facing classes (LSMVectorIndex, VectorUtils). It is cheap and idempotent, and removes the dependency on LocalDatabase init order.

3. Minor

  • isVectorApiCompiled() is just !isNativeImage(). A JVM without C2 (-Xint, TieredStopAtLevel=1) has the same slowness. That is out of scope, but worth a comment.
  • The static block mutates a global system property as a side effect of class loading. That is acceptable here, and the user override is respected.

4. Tests

  • The decision logic is well covered, in the repo assertThat style.
  • configureJVectorProvider() itself (the setProperty side effect) is untested. A small test is possible: save and restore the property, and assert it is left untouched on a JVM.

No security concerns and no new dependencies. Once the native end-to-end result is confirmed (point 1), this looks good to me.

@codacy-production

codacy-production Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 21 complexity

Metric Results
Complexity 21

View in Codacy

🟢 Coverage 95.00% diff coverage · -5.05% coverage variation

Metric Results
Coverage variation ✅ -5.05% coverage variation
Diff coverage ✅ 95.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (6b1f278) 236685 204627 86.46%
Head commit (bc21089) 269411 (+32726) 219309 (+14682) 81.40% (-5.05%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#10077) 40 38 95.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

…upport

The LocalDatabase hook only worked while LocalDatabase initialized before the
first jvector provider lookup. VectorApiSupport.jvectorProvider() now applies
the native-image rule in a lazy holder before it resolves jvector's provider,
and all seven ArcadeDB call sites use it, so none of them can resolve the
provider first. Adds tests for the configureJVectorProvider() side effect,
and documents why -Xint is not probed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robfrank

Copy link
Copy Markdown
Collaborator Author

Review addressed in bc21089.

1. Native-image init timing - checked, the build-time path does not apply. native/pom.xml initializes only org.slf4j.* and Netty's CleanerJava24Linker at build time, and the jvector jar ships no native-image.properties, so LocalDatabase, both SIMD providers and jvector itself initialize at run time. The native end-to-end benchmark without -D is still pending and will be posted here before merge.

2. Ordering assumption - fixed. VectorApiSupport.jvectorProvider() applies the native-image rule in a lazy holder before it resolves jvector's provider. All seven ArcadeDB call sites now use it (LSMVectorIndex, ArcadePageVectorValues, VectorUtils x3, SQLFunctionVectorAvg, JVectorUtils), so none of them can resolve the provider first. After initialization the hot paths pay a static field read and nothing else. The LocalDatabase hook stays, for jvector classes that reach the provider from inside jvector.

3. -Xint / no C2 - documented on isVectorApiCompiled(): jvector already detects an emulated-client VM itself and falls back to its scalar provider, so a second probe isn't worth it.

4. Untested side effect - added configuringOnAJvmLeavesTheJVectorPropertyAlone (saves and restores the property, checks that both an unset and an explicit value are left untouched on a JVM) and everyCallSiteGetsJVectorsOwnProvider.

Engine vector, sparse-vector, time-series and Graph-OLAP suites: 3027 tests, 0 failures.

@claude

claude Bot commented Oct 15, 2026

Copy link
Copy Markdown

Review

The approach is sound. It's small, the explicit -Djvector.vectorization_provider override still wins, and the JVM behaviour is unchanged. My git grep of main sources for VectorizationProvider.getInstance and jdk.incubator.vector found no other unguarded entry points.

Main concern: the pending native check

  • The fix depends on LocalDatabase's static initializer running before jvector resolves its provider. The unit tests can't prove that in a native image, and the PR says the native rebuild and benchmark are still pending. I'd hold the merge until that result is posted.
  • VectorApiSupport.jvectorProvider() also calls configureJVectorProvider(), so every ArcadeDB call site is covered. The LocalDatabase hook only matters for jvector classes reached from inside jvector.
  • A caller could use jvector directly without going through LocalDatabase or VectorApiSupport, for example a test or embedded code that builds an index before opening any database. That caller would still resolve Panama first. This is acceptable, but worth a note in the Javadoc.

Minor points

  • Import ordering: import com.arcadedb.utility.VectorApiSupport; was inserted at the top of the import block in SQLFunctionVectorAvg, ArcadePageVectorValues, LSMVectorIndex and VectorUtils. Please place it in alphabetical position to match the surrounding code.
  • System.setProperty mutates process-global state from a LocalDatabase static initializer. It's idempotent, so it's fine. Putting the call in LocalDatabase ties a vector concern to the core class. A server or engine bootstrap hook would be cleaner, but LocalDatabase is the one choke point every path shares, so I'm fine with it.
  • isVectorApiCompiled() is currently just !isNativeImage(). The Javadoc is honest about this. The -Xint and TieredStopAtLevel=1 cases are not covered for the ArcadeDB SIMD ops. That's a reasonable trade-off.
  • Tests: select(true) constructs SimdTimeSeriesVectorOps or SimdGraphOlapVectorOps. If the test JVM runs without --add-modules jdk.incubator.vector, the LinkageError fallback would return the scalar ops and the assertion would fail. The existing SIMD tests probably already rely on that flag, so this is only worth confirming.
  • VectorApiSupportTest.configuringOnAJvmLeavesTheJVectorPropertyAlone mutates a system property. Other tests in the same JVM may read it. It restores the property in a finally, which is fine. Surefire's default forks are sequential, so I don't expect a problem.

Overall this looks good once the native benchmark confirms the ordering.

@robfrank

Copy link
Copy Markdown
Collaborator Author

Native end-to-end check (review point 1): passed.

Native image built from this branch at bc21089 (GraalVM CE 25.0.2, macOS aarch64), started without -Djvector.vectorization_provider. Same benchmark as the PR description: 20k vectors x 384 dims, COSINE, vector.neighbors k=10, median of 59 queries after 20 warmup queries.

Native image Graph build (first query) neighbors median / p90
before the fix (Panama, auto) 178.3 s 13.7 / 15.5 ms
this branch, no flag 5.7 s 3.6 / 5.7 ms

The Java incubating Vector API enabled. Using PanamaVectorizationProvider. line no longer appears in the server log. jvector logs nothing when its scalar provider is forced, so the timings are the evidence.

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.32%. Comparing base (6b1f278) to head (bc21089).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...in/java/com/arcadedb/utility/VectorApiSupport.java 69.23% 1 Missing and 3 partials ⚠️
...e/timeseries/simd/TimeSeriesVectorOpsProvider.java 90.00% 0 Missing and 1 partial ⚠️
...in/java/com/arcadedb/index/vector/VectorUtils.java 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main   #10077   +/-   ##
=========================================
  Coverage     78.32%   78.32%           
  Complexity     4538     4538           
=========================================
  Files          2235     2237    +2     
  Lines        236685   236710   +25     
  Branches      51237    51239    +2     
=========================================
+ Hits         185384   185410   +26     
+ Misses        32098    32094    -4     
- Partials      19203    19206    +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

robfrank added a commit that referenced this pull request Oct 21, 2026
…compiled Vector API (#10077)

* fix(#10072): a native image uses scalar vector math instead of the uncompiled Vector API

A GraalVM native image does not compile jdk.incubator.vector calls into SIMD
instructions: each call runs the incubator's pure-Java lane loops, several
times slower than plain scalar code. jvector still picked its
PanamaVectorizationProvider there, so the graph build of 20k 384-dimension
vectors took 178 s instead of 6.5 s.

VectorApiSupport detects a native image. LocalDatabase's class init points
jvector at its scalar provider before any jvector class resolves one, unless
the user set jvector.vectorization_provider. The Graph-OLAP and time-series
SIMD providers pick their scalar ops in a native image too.

The LocalDatabase hook only worked while LocalDatabase initialized before the
first jvector provider lookup. VectorApiSupport.jvectorProvider() now applies
the native-image rule in a lazy holder before it resolves jvector's provider,
and all seven ArcadeDB call sites use it, so none of them can resolve the
provider first. Adds tests for the configureJVectorProvider() side effect,
and documents why -Xint is not probed.

(cherry picked from commit ac89255)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

native-image GraalVM native image performance vector Vector index and embedding search

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native image: vector search runs the Vector API without SIMD, 6-27x slower than the scalar fallback

1 participant