← Back to Pull requests

Batch native Highway operations to reduce Java/native overhead #761

Closed
unknown closed this pull request without merging on Oct 16, 2026 22:52 UTC
View on GitHub
unknown unknown commented on Oct 16, 2026 00:17 UTC
Author

Goal and changes

Reduce Java/native call overhead and temporary allocation in the Google Highway backend, especially during PQ training and encoding. Builds on the native kernels and provider selection already merged in #753 and #751.

  • Batch closest-centroid scans and KMeans initialization; fuse centroid normalization and assignment updates.

  • Use lazy array-backed native views and direct byte/scalar access to avoid temporary wrappers and allocations.

  • Batch NVQ growth-rate search, use SIMD for NVQ setup/quantization, and keep cosine results packed.
  • Performance results

    Both arms use native Highway AVX-512. Each cell shows main → this PR; bold marks the winning measurement.

    PQ training is approximately 1.9–3.2× faster, and encoding 2.3–3.5× faster. Total construction is lower in every comparison. Single-thread query throughput improves in seven of eight dataset/JDK combinations. I confirmed that recall@10 is essentially unchanged.

    Construction — seconds, lower is better

    | Dataset | JDK | PQ training | PQ encoding | Graph/write | Total process |
    |---|---:|---:|---:|---:|---:|
    | MPNet | 22 | 4.76 → 2.56 | 3.27 → 0.94 | 53.01 → 29.89 | 65.42 → 37.74 |
    | MPNet | 25 | 6.93 → 2.41 | 3.15 → 0.94 | 32.05 → 32.60 | 46.52 → 40.15 |
    | Ada002 | 22 | 12.29 → 4.29 | 6.20 → 1.93 | 53.92 → 55.74 | 79.46 → 69.19 |
    | Ada002‡ | 25 | 10.24 → 3.47 | 5.99 → 1.84 | 47.11 → 45.29 | 69.56 → 57.18 |
    | Cohere† | 22 | 9.31 → 2.87 | 4.28 → 1.42 | 40.76 → 43.84 | 59.82 → 53.78 |
    | Cohere | 25 | 7.87 → 2.68 | 4.07 → 1.22 | 37.10 → 41.29 | 54.20 → 50.32 |
    | OpenAI3072 | 22 | 23.68 → 7.55 | 13.53 → 5.80 | 106.51 → 116.92 | 156.09 → 142.88 |
    | OpenAI3072 | 25 | 20.42 → 6.85 | 13.62 → 5.45 | 119.61 → 118.11 | 165.65 → 143.05 |

    Queries — QPS, higher is better

    | Dataset | JDK | 1 thread, 1× | 1 thread, 2× | 8 threads, 1× | 8 threads, 2× |
    |---|---:|---:|---:|---:|---:|
    | MPNet | 22 | 12,180 → 13,136 | 9,324 → 10,021 | 97,973 → 108,674 | 68,327 → 82,580 |
    | MPNet | 25 | 12,114 → 13,682 | 9,393 → 10,480 | 89,620 → 92,609§ | 72,653 → 70,871§ |
    | Ada002 | 22 | 7,020 → 7,186 | 5,492 → 5,666 | 54,180 → 60,928 | 43,811 → 48,857 |
    | Ada002 | 25 | 6,903 → 7,365 | 5,443 → 5,812 | 60,556 → 58,350§ | 46,388 → 50,278 |
    | Cohere | 22 | 10,423 → 9,958 | 7,905 → 7,723 | 82,282 → 80,848 | 61,963 → 62,848 |
    | Cohere | 25 | 8,420 → 10,661 | 6,530 → 8,080 | 81,661 → 84,463§ | 61,133 → 66,717 |
    | OpenAI3072 | 22 | 3,295 → 3,652 | 2,752 → 2,994 | 20,433 → 23,676 | 18,080 → 23,245 |
    | OpenAI3072 | 25 | 3,295 → 3,768 | 2,712 → 2,996 | 25,044 → 24,760 | 22,230 → 23,384 |

    Graph/write remains slower in several cases. The fresh Cohere/JDK22 repeat shows 7.6% higher graph/write time, with 10.1% lower total construction time; its cause is not established. Cohere/JDK22 single-thread QPS is 2.3–4.5% lower.

    Method: BenchYAML, JDK22/25, four nominal-1M datasets, 128 GiB heap, 48 construction workers, deferred batch writer, FusedPQ width8/K256 uncentered/unweighted, NVQ with two 8-bit subvectors, V6 M32/ef100, hierarchy/refinement enabled, pruning and assertions disabled. Every construction uses a fresh codebook and graph. Queries use resident graphs, pinned 1-/8-thread execution, top10 at 1×/2× overquery, and three warmup/measurement rounds.

    † Fresh A-B-B-A medians for main eba7bd4e versus latest PR head cebb94f8, replacing the earlier Cohere/JDK22 construction row.

    Other rows compare historical main eba7bd4e measurements with the f65c91f8 rerun on the same server. The latest scalar fix received separate correctness/microbenchmark validation and the Cohere construction repeat; the full query sweep was not repeated after it.

    Test and methodology

  • Full reactor tests passed on JDK 22 and 25: 496 tests per JDK for this PR, zero failures/errors, five skips. The native-module suite also passed with automatic dispatch, AVX2, the scalar tier, and Java fallback on both JDKs. Both original CI test failures were reproduced before applying the fixes. Coverage includes native PQ/NVQ operations, lazy storage, byte reads, and provider/ABI fixtures. Standalone native C++ tests were not run locally because GoogleTest was unavailable. Apache RAT license checks also passed.

  • Completed 80 primary benchmark stages plus 12 noisy-query repeat passes, with no stage failures. Separate memory/GC passes were collected as supporting data.

  • Standard BenchYAML on the same Xeon 6985P-C server; JDK 22.0.2/25.0.2; independent fresh codebooks/graphs; 128 GiB maximum heap; 48 construction workers; deferred batch writer; FusedPQ width8/K256 uncentered/unweighted; NVQ2; V6 M32/ef100; hierarchy/refinement enabled; pruning disabled; resident query graphs; 1-/8-thread queries pinned to CPU0/CPU0–7; assertions disabled.
  • Diff: 634 lines (+475 / -159) across 7 files Reviewer: tlwillke Review duration: 1354m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 634 lines diff across 7 files
    0.50
    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.386
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #761"
    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: 50.4% (MEDIUM) · Higher = larger blast radius
    50.4%
    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: 21.8% · Safe to merge
    21.8%