Repository navigation
Description
Summary
ADR 0005 defers the Vector API, partly because a hard --add-modules jdk.incubator.vector would tax every consumer. This issue covers the read side: which loops get an optional Vector API kernel, and which stay scalar loops shaped for C2. The write side is #484.
Selection rule (prime directive: parity with Rust). The Rust reference uses SIMD at two levels (survey: #484 (comment)):
- Level 1, scalar loops shaped for the auto-vectorizer. All encode/decode work: the
fastlanescrate (bit-pack, delta, FoR, RLE), casts, ALP. No intrinsics. - Level 2, hand-written SIMD with one-time CPU dispatch (
vortex-buffer/src/dispatch.rsCpuKernel,fearless_simd). Used only for selection and bitmap work: filter compress, take, bitmap pack/popcount/select, UTF-8.
A Java kernel gets a Vector API implementation only if (a) the corresponding Rust operation is level 2, or (b) C2 provably fails to vectorize a level-1 loop that LLVM does. Everything else stays scalar and C2-shaped. ADR 0005's bar still applies on top: ≥ 10% over the best scalar loop on two architectures, and hot in a real profile.
Level 2: Vector API candidates (Rust uses hand-written SIMD)
Ranked by fit to the Java API:
| # | Operation | Rust | Java Vector API | Java call site |
|---|---|---|---|---|
| R1 | Filter compress: mask-select fixed-width values | arrays/filter/execute/simd_compress/ (AVX-512 maskz_compress, AVX2 permutevar8x32, NEON vqtbl1q_u8 + LUT, portable swizzle_dyn for 1/2-byte); rung 3 of the filter/execute/buffer.rs ladder |
XxxVector.compress(VectorMask) (JDK 19+, intrinsified on AVX-512/SVE; NEON lowering unverified) + VectorMask.fromLong |
none today: row filtering is fused or per-row, scans prune by zone only (see comment) |
| R2 | bool → bitmap pack (collect_bool) |
vortex-buffer/src/bit/pack.rs (AVX-512BW vptestmb, pmovmskb, NEON ushl + addp) |
compare(...) → VectorMask.toLong() |
predicate result → validity/selection bitmap |
| R3 | Small-table take: u8 codes, ≤ 16 one-byte values | fixed_width/take/small_table/{neon,avx2}.rs (vqtbl1q_u8, vmaxq_u8 bound check) |
ByteVector.selectFrom / rearrange |
DictEncodingDecoder with small u8 dictionaries; its code bound check (vmaxq_u8) shipped as maxUnsigned (fbecfb45) |
| R4 | Bitmap popcount / nth-set-bit select | bit/count_ones.rs, bit/select.rs, vortex-mask/src/intersect_by_rank.rs (SIMD popcount, BMI2 pdep/tzcnt) |
Long.bitCount is already a C2 intrinsic: measure only |
mask true-count, row-range selection |
| R5 | Take / gather | fixed_width/take/avx2/ (AVX2 gather, 4/8-byte only) |
fromArray(..., indexMap, ...) exists only for heap arrays, not MemorySegment. Weak fit, not proposed |
n/a |
| R6 | UTF-8 validation | simdutf8 |
The JDK String decode is already intrinsified (countPositives). No action |
n/a |
Each candidate needs JMH A/B (-f 3, ClassName.methodName) at selectivities 1%/50%/99% where relevant, plus a JFR profile of a real filtered scan (e.g. JavaVsJniFilterBenchmark, CalciteBoundaryAggregateBenchmark) showing the loop is hot.
Not proposed
- Dictionary gather (except the R3 small-table case),
LazyAlp*/FoR/ZigZag: level 1 in Rust, and C2 already handles the clean ones. - Any
DecodeContext/ReadOptionsflag (Strategy B).
Design constraints
- Bit-identical to the scalar path. Differential test in
SimdOperationsTest(hardwood pattern): seeded random plus edge cases (empty, tail,Long.MIN_VALUE, unsigned, NaN/-0.0). - Opt-in only, scalar default. A link failure falls back silently (DEBUG log).
- Security contract unchanged: bounds are checked before the kernel, and a kernel throws only
VortexException. - ADR 0005 (status and evidence),
docs/reference.md, and CHANGELOG are updated in the same commit.
Acceptance
- Packaging (hardwood-style, opt-in):
SimdOperationsseam withAutoVectorizedSimdOperations(default) andVectorApiSimdOperations, chosen once per JVM bySimdOperationsSupport - Level 1: scalar, C2-shaped loops (no Vector API):
AutoVectorizedSimdOperationsis the Rust-parity default for all eleven ptypes - Delta undelta: JMH baseline vs pre-interchange, C2 vectorization confirmed (perfasm/JFR), result recorded
- Fused filter-aggregate: plain-Java branch-free compare loop tried first (Rust analogue:
compare_fused.rs; keep doubleSUMsequential), result recorded - R1–R3: JMH baselines on M5 + one x86 machine before any kernel
- Vector kernel only if rule (a)/(b) holds and it is ≥ 10% over the best scalar loop on both machines
- Differential test against the scalar path
- ADR 0005 updated with the numbers either way
Activity
[-]perf(reader): optional Vector API kernels for fused filter-aggregate and Delta decode (hardwood-style, opt-in)[/-][+]perf(reader): SIMD kernels mirroring Rust: C2-shaped scalar loops, opt-in Vector API for filter compress/bitmap/small-table take[/+]dfa1 commentedon Oct 9, 2026
Read-side survey + first rule-(b) evidence (2026-10-09)
Dict code bound check: shipped scalar, Vector API measured
DictEncodingDecoder#validateCodesInRange(every dict decode scans every code formax < poolLength) is our equivalent of Rust'svmaxq_u8bound check intake/small_table/neon.rs. Committed asSimdOperations#maxUnsigned(fbecfb45).MaxUnsignedBenchmark, M5 / NEON (MaxVectorSize=16), 1M codes, µs/op:longmax)UMAXMAXwith sign bit flipped(
-f 3for the first two columns,-f 2for the Vector API.)Findings:
intor thelongdomain. The scalar kernel gets 2.3× from four independent accumulators (instruction-level parallelism, not SIMD).VectorOperators.UMAXisn't intrinsified on aarch64 in JDK 25. It runs a Java fallback that's slower than scalar, with cost proportional to element width. XOR the sign bit, thenMAX, maps to NEONsmaxinstead. Every Vector API kernel needs a JMH row per operator, not just per kernel.longs. That's 4.6× over the scalar kernel. U16 is 2.2× better. U32 gains nothing, because C2 already vectorizes theintloop.The experiment needs
--add-modules jdk.incubator.vectorat compile time and-jvmArgsAppend --add-modules=jdk.incubator.vectorat run time. It's not committed; the core seam doesn't load the incubator module yet.Read-side loop inventory (what else maps to Rust's level 2)
BitpackedEncodingDecoderunpackLoop{8,16,32,64}fastlanesunpack (level 1)DictFiltercode scans (seg.get(i) == only,match[code]) + per-rowfold.acceptcollect_boolbyte → bitmap (pack.rs,vptestmb/pmovmskb/ NEONushl+addp)ByteVector.eq(only).toLong()→ iterate set bits. Same C2 widening problem expected. Use signed ops onlyFusedFilterSum/FusedFilterAggregate(selectedLong+getBooleanper row)compare_fused.rs(compare during unpack, then onetranspose_bits)DictEncodingDecoder#rowValidity(per-rowgetBoolean+setBit, only when the pool has nulls)BoolEncodingDecoder#realign(byte-at-a-time shift)BitBufferworks on u64 wordslong-at-a-time funnel shift. Low priority (only when offset ≠ 0)simd_compress/Compute#matches); scans prune by zone only. Revisit if a selection-vector API appearsLazy{For,ZigZag,Alp}*Array#materializedfa1 commentedon Oct 9, 2026
Progress and plan (branch
perf/simd-kernels, not pushed)Done: Delta undelta (candidate 2) — plain Java, no Vector API needed
undeltaChunknow lives incore.simd.SimdOperations(VectorSupport.operations()is the single seam; scalar implementation only).DeltaEncodingDecoderdelegates to it. Loops are swapped to rows-outer / lanes-inner, and only the result is masked (the low bits of a sum depend only on the operands' low bits).SimdKernelBenchmark.undelta, 256 chunks,-f 3, Apple M5:So the loop-interchange experiment this issue asked for ran first, and it already gives 1.6–2×. A Vector API version of undelta now has to beat these numbers, not the old ones. Commit
b18ad842. Reader/writer Delta tests and the Rust interop ITs pass.scatterChunk(permutation scatter) is unchanged and still bounds the end-to-end gain.Next: fused filter + aggregate (candidate 1), scalar first
FusedFilterAggregate#foldLongDomain/FusedFilterSumrun a per-row loop: oneLongPredicatecall per leaf, an earlycontinue, a validity check, thensum +=and min/max with afoundbranch. C2 cannot vectorize that.Plan, same shape as the other kernels:
SimdOperationsfor the primitive case (long/double column vs constant, afterPrimitiveFilter.lowerLong): compare a block against the constant and fold only the matching rows, with no predicate object per row. AddSimdKernelBenchmarkrows at 1% / 50% / 99% selectivity for the baseline.trueCount, maskedreduceLanes), kept only if it beats the scalar kernel by >= 10% on two architectures.Parity risk unchanged: double
SUMin lane order rounds differently from a sequential loop, so it stays sequential (or must match Rust's accumulation order). Integer paths are exact.Not planned: the reader's bit-unpack loops.
BitpackedEncodingDecoderalready has per-widthunpackLoop16/32/64written for C2 (ADR 0005); revisit only if a profile shows them hot.dfa1 commentedon Oct 9, 2026
Design and rationale: ADR-0005 (previously tracked in TODO.md, now retired in favor of GitHub Issues).
dfa1 commentedon Oct 24, 2026
Tried and reverted (2026-10-24): generated FastLanes unpack kernels in Rust's
unpack!shape, one per (type width, bit width): per lane each packed word loaded once, every row's shift a constant.RealFileScanBenchmarkon the seven real files, against main: every file regressed. With u8/u16/u32 kernels: tpchorders-53%,appian-order-37%,store_sales-35%,bi-corporations-28%,imdb-job-title-26%. With u8/u16 only:appian-order-27%,orders-5%.orders: the kernels were C2-compiled, but the FFM per-access checks (MemorySessionImpl.checkValidStateRaw,checkBounds) were hot leaves. In a straight-line body of 50+ segment accesses they are not hoisted, while the existing row-outer loops (one lane loop per row) get them hoisted.Related, measured the same day: on JDK 25, C2 does not vectorize a loop that loads one native segment and stores another (two-segment
out[i] = in[i] & maskis 3.7x slower than over heap arrays); JDK 26 does. So on the JDK 25 baseline, explicit SIMD (the opt-in Vector API path) is the remaining lever for unpacking.