← Back to Pull requests

ASH: support every similarity at every setting; faster Panama scoring for 2–9 bits #831

Closed
unknown closed this pull request without merging on Nov 25, 2026 04:54 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 00:55 UTC
Author

ASH says it supports DOT_PRODUCT, COSINE and EUCLIDEAN, but the tests covered only 1–4 bits and a few scoring paths. This PR tests every supported setting, fixes what the tests found, and replaces the slow Panama scoring paths.

Tests


  • New TestASHMetricMatrix covers all three similarities at:

  • - 1–9 bits, 1 and 3 landmarks, ITQ and RANDOM
    - in-memory, symmetric, fused (block sizes 8/16/32), separated and streaming scoring
    - every kernel mode (singleKernel/blockKernel scalar/simd/auto, gatheredScoring)
  • Every path must match the scalar reference, and the reference must estimate the exact similarity, more closely as the width grows. About 25 s per provider.

  • New PanamaASHOffsetBinaryDotTest checks the new kernels against an independent decoder at every width and many lengths, with codes anywhere in an array, and checks they give the same bits before and after the JIT compiles them.
  • Fixes found by the tests


  • MutableASHVectors: symmetric batch scoring threw a null pointer when its batch kernel was off (for example at 1 bit).

  • ASHVectors.blockScorerFor(query): threw a null pointer with -Djvector.ash.gatheredScoring=true.

  • OnDiskGraphIndex.View: a fused score function made on one view and used to search through another returned wrong neighbors (0 of 10 correct in one case). The searching view now reads its own neighbor list when the score function loaded it elsewhere.

  • Prepared 2/4-bit scoring (JDK 25 Panama): a code ending its array was scored through a scalar tail with a different summation order, so the same code could score differently depending on where it was stored (116–482 of 800 test codes, more at 4 lanes). It now uses a padded copy like the other kernels, TestASHCodes checks it, and 2/4-bit single scoring is 3–5% faster.

  • Panama vector shapes: the decode tables and kernels now apply only at 4, 8 or 16 float lanes, and symmetric SIMD needs 128-bit vectors; other shapes score in Java. The provider failed to load with 64-bit vectors (-XX:MaxVectorSize=8, also in 4.1.0-rc.1), and 8 and 9-bit decoding was wrong at 32 lanes.
  • Faster scoring


  • 3 and 5–9 bits were scored in plain Java on Panama. A new kernel decodes the fields in vector registers. Native uses it too, because it is faster than the native LUT kernel.

  • 2 and 4 bits on JDK 22 (Panama) used vector gathers, which are slow on Ice Lake. They now use the same decode kernel, and the gather kernel is removed. JDK 25 keeps its existing kernel, which is faster there.

  • Fused 3 and 5–9-bit neighborhoods (Panama, or more than one landmark) now sum each neighbor's INT8 dot product in SIMD. Scores are unchanged bit for bit.

  • Symmetric (code-to-code) scoring at 3 and 5–9 bits, which graph construction uses, decoded each field in plain Java with either provider. A new Panama kernel decodes the fields in registers and sums the exact integer products, so scores are unchanged bit for bit. Native uses it until native kernels exist (#835). The 1, 2 and 4-bit symmetric kernels are unchanged.

  • The query's nibble table is built only where something reads it, which skips it for 3 and 5–9 bits on SIMD backends (codeGroups × 16 floats per query, 7,680 at 5 bits and d=384).

  • Every new kernel adds lanes in a fixed order, so a score does not depend on the JIT tier or on where the code sits in memory.

  • Each kernel has one copy of its vector operations, and the fixed-order lane sum is straight-line code. With unrolled copies, C2 compiled some of them as heap-allocating calls in some JVMs, which ran 1.6–4× slower for the JVM's whole life.
  • Results


    ns per vector, d=384, JDK 22, old = 4.1.0-rc.1. One thread, JVM pinned to 4 cores, one width per JVM, median of 3 timed rounds, best of 2 JVMs.

    | | Ice Lake (32 cores) | Ice Lake (8 cores) | GNR (48 cores) |
    |---|---|---|---|
    | 3, 5–9 bits, Panama, single | ~740–1,410 → ~55 | ~720–1,380 → ~52 | ~460–920 → ~36–40 |
    | 3, 5–9 bits, Panama, fused upper layers | ~610–990 → ~75–81 | ~590–970 → ~71–75 | ~370–670 → ~53–59 |
    | 3, 5–9 bits, Panama, fused neighborhoods | ~790–1,000 → ~85–88 | ~750–950 → ~80–82 | ~470–600 → ~54–56 |
    | 3, 5–9 bits, native, single | 190–526 → ~58–61 | 92–346 → ~55–56 | 51–249 → ~39–44 |
    | 2 bits, Panama, single | 293 → 78 | 134 → 75 | 80 → 55 |
    | 4 bits, Panama, single | 287 → 78 | 134 → 74 | 83 → 55 |
    | 3, 5–9 bits, symmetric (graph construction) | 1,210–1,550 → 85–95 | — | — |
    | 1/2/4 bits otherwise | no change | no change | no change |

    The symmetric row is ns per pair at 5 and 8 bits, JDK 22 and 25, native and Panama, 3–6 JVMs each. JDK 25 gives the same 3/5–9-bit gains. JDK 25 Panama keeps its 2/4-bit kernel; its 2-bit single score is faster with the new lane sum (88 → 65 on Ice Lake (32 cores)). Every apparent 1/2/4-bit slowdown was re-run across several JVMs and was run-to-run noise.

    End to end, 1M vectors, 5 bits


    Ice Lake (32 cores), JDK 22, native provider, 4.1.0-rc.1 → this PR. The repo's ASH vs PQ study setup (run-ash-pq-benchmark.sh) with bitsPerDimension: 5 and encodedBits to match; build on all cores, then one pass of cold queries on 1 core.

    | | ada002-1M (1536 dims) | dpr-gemma-1m (768 dims) |
    |---|---|---|
    | Build time | 631 s → 63 s (10×) | 323 s → 39 s (8.3×) |
    | QPS, 1 core, overquery 1× | 4,175 → 6,324 (+51%) | 7,005 → 9,689 (+38%) |
    | QPS, 1 core, overquery 2× | 3,420 → 4,806 (+41%) | 5,651 → 7,229 (+28%) |
    | Recall@10, 1× / 2× | 0.848 / 0.930 → 0.850 / 0.931 | 0.888 / 0.978 → 0.889 / 0.980 |
    | p50 latency, 1× | 2.06 → 1.35 ms | 1.22 → 0.87 ms |

    Recall differs only by the run-to-run variation of the parallel build; the scores themselves are unchanged.

    Testing


  • ASH suites on JDK 22 and 25, native and Panama, and JDK 11 (-Pjdk11), on Ice Lake (32 cores).

  • TestASHMetricMatrix passes on JDK 22 and 25, native and Panama.

  • Panama ASH suites also pass with -XX:MaxVectorSize=32 (8 lanes, as on AVX2), =16 (4 lanes) and =8 (2 lanes, the Java fallback), with assertions on, on JDK 22 and 25. At 2 lanes, PQ's assembleAndSum still rejects 64-bit vectors, as it does in 4.1.0-rc.1.

  • No new failures compared with 4.1.0-rc.1. NativeASHInt8ProjectionTest fails under forced Panama there too, and so do the intermittent JDK 25 Panama tests that compare floats bit for bit across JIT tiers (TestASHEuclidean, TestASHCosine, TestStreamingASHIndex).

  • On JDK 25, C2 adds SIMD lanes in a different order than the interpreter and C1, so a float sum can change in its last bit once compiled. TestASHTrainingSetup.unitLengthInputGivesTheSameModelAsTheEarlierUnitLengthTraining and TestMutableASHVectors.concurrentlyAddedVectorsScoreBitForBitAsAFixedCollection now allow exactly the differences that can cause, and pass 10 of 10 on JDK 22 and 25 at 4 lanes and full width. Production code is unchanged by this; making those sums fixed-order cost 1–3% in query projection.

  • TestASHSymmetricScorer had a stale check that failed with -Djvector.vectorization_provider=native; it is removed, so the test now covers native at every width.
  • Known issues


  • Whole-JVM slow modes on JDK 22, Ice Lake (32 cores), JVM confined to one core: 16 of 22 JVMs with this PR's first kernels, 1 of 30 with the final ones. With 4 cores, none in about 140 JVMs on both Ice Lake machines. The margin is small: 0 of 12 slow at the default -XX:MaxInlineLevel (15), 2 of 12 at 14 and 4 of 12 at 13, so a kernel reached through a deeper call chain can still lose its vector intrinsics. Hoisting the kernels' broadcasts out of their loops removed them, but cost 4–19% on other paths, so it is not included.

  • Native has no kernels of its own for 3 and 5–9 bits yet; it uses the Panama ones (#835).

  • Native 4-bit on JDK 25 varies by about 10% from one JVM to the next (also in 4.1.0-rc.1); not changed here.

  • 3-bit non-fused block scoring, whose LUT kernel is unchanged, matches 4.1.0-rc.1 when timed alone (29.2 ns in 6 of 6 JVMs on Ice Lake (32 cores)). After fused L0 scoring in the same JVM it is 31.0 ns in 3 of 6 JVMs. 5–9 bits match 4.1.0-rc.1 either way.
  • Docs


    docs/ash-configuration.md now says every similarity works at every setting, and describes the per-width kernels, symmetric ones included.
    Release notes: docs/release notes/4.1.0-rc.2/831.performance.md and 831.bugfix.md.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: MarkWolters Review duration: 1678m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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 #831"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%