Inline the Panama dot product for short slices #842
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #842"
general
weight: 0.35
MarkWolters
Follow-on to #816, as suggested in its review.
PanamaVectorUtilSupport.dotProductPreferredis 421 bytes of bytecode, over C2's 325-byte limit for hot methods, so it is never inlined ("hot method too big"). Every dot product on a slice one to three SIMD vectors wide, such as a PQ subvector, paid for a real call. #816 added a check for exactly one vector at the top ofdotProduct; this adds a path for slices up to three vectors wide, for example 8 or 12 floats on 128-bit SIMD, 16 or 24 on AVX2 and 32 or 48 on AVX-512. Building the per-query PQ table (calculatePartialSumsforDOT_PRODUCTandCOSINE) makes one such call per centroid.Change
dotProductsends slices longer than one vector and shorter than four to a newdotProductShort(inlined). It sums the first two vectors in separate accumulators, asdotProductPreferreddoes, so their multiply-adds do not wait on each other; a single running sum measured up to 50% slower on JDK 25. A partial last vector of four or more floats (on AVX2 or AVX-512) finishes on the existing 128/256-bit kernels through a smalldotProductNarrowhelper instead of one float at a time; shorter leftovers stay scalar, since 64-bit float vectors are slower than scalar code on 128-bit ARM. Results are the same up to float rounding.dotProduct, unchanged, so single-vector slices run exactly as before.dotProductPreferredas before; its two branches for shorter slices, now unreachable, are removed (full-vector dot timings unchanged).COSINEtables are built from the same dot products and gain too.EUCLIDEANtables are unchanged: theirsquareDistancePreferred(178 bytes) is already small enough to inline.Where it applies
The Panama provider on any CPU; the slice sizes follow the SIMD width:
| Platform | Register | Slices that gain | Tested |
|---|---|---|---|
| x86 AVX-512 | 16 floats | 32-48 floats | Ice Lake, GNR |
| x86 AVX2 | 8 floats | 16-24 floats | Ice Lake, GNR (
-XX:UseAVX=2) || ARM NEON / 128-bit SVE | 4 floats | 8-12 floats | Graviton4; Apple silicon (correctness, inlining) |
Where the native provider is in use, nothing changes.
Tests
#816's
testDotProductOnShortSlicesWithOffsetsnow also covers 12, 23, 24, 47, 48, 63 and 64 floats, so every one-to-three-vector slice shape is checked against the scalar provider at several offsets on 128-bit, AVX2 and AVX-512.Results
End to end on ARM (Graviton4, 16 cores, JDK 22, Panama). PQ at the same code size as 2-bit ASH (32X; 7-8-float subspaces, two NEON registers), on-disk fused graph with NVQ rerank, top 10, 8 search cores, 3 fresh JVMs per build, alternating; mean QPS:
| Dataset (1M) | Overquery | Recall@10 | QPS before | QPS after | Change | p50 latency (ms) |
|---|---|---|---|---|---|---|
| MPNet (768d) | 1 | 0.640 | 25,674 | 32,536 | +27% | 0.29 -> 0.23 |
| MPNet (768d) | 2 | 0.807 | 18,365 | 26,548 | +45% | 0.50 -> 0.28 |
| Cohere v3 (1024d) | 1 | 0.594 | 20,562 | 25,912 | +26% | 0.38 -> 0.29 |
| Cohere v3 (1024d) | 2 | 0.785 | 18,066 | 18,326 | +1% | 0.42 -> 0.58 |
| ada-002 (1536d) | 1 | 0.552 | 14,326 | 18,306 | +28% | 0.54 -> 0.42 |
| ada-002 (1536d) | 2 | 0.753 | 13,281 | 15,554 | +17% | 0.58 -> 0.50 |
| CAP (1536d) | 1 | 0.494 | 15,016 | 19,428 | +29% | 0.51 -> 0.39 |
| CAP (1536d) | 2 | 0.689 | 13,598 | 17,325 | +27% | 0.57 -> 0.44 |
Recall is identical before and after. In every row without an asterisk, every run after the change beat every run before it. \* One run after the change landed in a slow JVM mode that both builds show on ARM (it predates this change); in the Cohere row the other two runs after the change (about 22,700 QPS) beat all runs before it. Single-core runs also favored the change but vary up to 2x between fresh JVMs of either build, so they are not shown.
On x86 the common 8-float subspaces are one AVX2 register (the #816 case, unchanged here) or less than one AVX-512 register, so x86 gains need coarser PQ: 16-24-float subspaces on AVX2 or 32-48-float subspaces on AVX-512. End to end with such settings (Cohere 1M, 1024 dimensions, single thread, PQ-scored search with on-disk FP rerank, top 10, rerankK 40, Ice Lake (8 cores), JDK 25, builds alternating; recall@10 identical):
| Width | PQ | QPS before | QPS after | PQ table per query |
|---|---|---|---|---|
| 512-bit | M=32 (32-float, 128x) | ~3,600 | ~4,280 (+19%) | 80 -> 37 µs |
| AVX2 | M=64 (16-float, 64x) | ~1,070 | ~3,330 (3.1x) | 602 -> 44 µs |
With 4 and 8 search threads on Ice Lake (32 cores), the 512-bit case rose 22% and 24%. The PQ table build alone took 13-46% less time with 32-float subspaces on Ice Lake (8 cores) and GNR (48 cores), JDK 22 and 25, and 62% less with 16-float subspaces at AVX2.
One-vector subspaces (16 floats at 512-bit, 8 at AVX2), smaller ones, and full-vector dot products at 64-1,024 dimensions are unchanged on both CPUs and JDKs, measured across 8-16 data placements per build with an identical-build control, since full-vector dot timings shift with cache-line alignment.
-XX:+PrintInliningshowsdotProductShort(289 bytes, under the 325-byte limit),dotProductNarrowand the 128/256-bit kernels inlined on AVX-512, AVX2 and NEON.Partial-last-vector subvectors, PQ table build time (Ice Lake (32 cores), JDK 22, 8 data placements, identical-build control within 1.3%): 20 and 24 floats at 512-bit -18% and -20%, 12 floats at AVX2 -40%. Whole-vector sizes (8, 16, 32 floats) and ARM (6, 7, 8 floats) are unchanged.