← Back to Pull requests

Wire calculatePartialSums to native SIMD via Panama FFI downcall #651

Closed
unknown closed this pull request without merging on Jun 15, 2026 04:07 UTC
View on GitHub
unknown unknown commented on Apr 02, 2026 03:44 UTC
Author

This change uses a native implementation of calculatePartialSums to accelerate PQ query scoring.
On ada002-100k with FUSED_PQ (numPQsubspaces/M =96, JDK build 23.0.1+11-39), it delivers 2–3× higher QPS and 40–65% lower mean latency across common overquery settings. Index build time, disk usage, and heap usage show no meaningful regression. The optimization is isolated to the PQ path; non‑PQ queries are unaffected.

Combined QPS and Latency Results (FUSED_PQ)

topK = 10

| Overquery | QPS (main) | QPS (native) | Speedup | Latency ms (main) | Latency ms (native) | Latency ↓ |
|----------|------------|--------------|---------|-------------------|---------------------|-----------|
| 1× | 8,987 | 26,101 | 2.9× | 0.462 | 0.171 | −63% |
| 2× | 8,361 | 21,706 | 2.6× | 0.505 | 0.202 | −60% |
| 5× | 7,199 | 14,364 | 2.0× | 0.590 | 0.292 | −51% |
| 10× | 5,796 | 9,640 | 1.7× | 0.731 | 0.431 | −41% |

topK = 100

| Overquery | QPS (main) | QPS (native) | Speedup | Latency ms (main) | Latency ms (native) | Latency ↓ |
|----------|------------|--------------|---------|-------------------|---------------------|-----------|
| 1× | 5,743 | 9,568 | 1.7× | 0.736 | 0.439 | −40% |
| 2× | 4,174 | 5,574 | 1.3× | 1.022 | 0.733 | −28% |
`

Summary of changes in this PR:

  • Wire calculatePartialSums in NativeVectorUtilSupport to a new Panama FFI downcall for the native calculate_partial_sums_f32_512` SIMD implementation.

  • Replace icelake-server gcc target with skylake-avx512 in build script (icelake-server isnt required to build our native code)

  • Remove global mutable state: eliminate initialIndexRegister, indexIncrement, maskSeventhBit, maskEighthBit globals and their constructor initializer; move mask constants (maskSeventhBit, maskEighthBit) to local scope inside lookup_partial_sums

  • Add shared reduce_add_128_ps and reduce_add_256_ps helper functions using proper horizontal-add sequences instead of store-to-array loops

  • Remove redundant if (length >= N) guards in all SIMD kernels — the loop body already handles the zero-iteration case correctly

  • Replace store-to-aligned-array horizontal reduction pattern with the new helpers across all 128- and 256-bit dot product and euclidean distance functions

  • Remove preferred_size parameter from dot_product_f32 and euclidean_f32; always dispatch to AVX-512 when length >= 16

  • Standardize inline annotations: replace __attribute__((always_inline)) inline with JV_FINLINE / JV_INLINE macros throughout
  • Diff: 327 lines (+245 / -82) across 4 files Reviewer: r-devulap Review duration: 106582m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.42) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 327 lines diff across 4 files
    0.42
    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.347
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #651"
    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: 42% (MEDIUM) · Higher = larger blast radius
    42%
    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: 18.2% · Safe to merge
    18.2%