← Back to Pull requests

Cut native call overhead on small vectors #836

Closed
unknown closed this pull request without merging on Nov 25, 2026 04:06 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 19:50 UTC
Author

The native provider made billions of tiny native calls on small vectors and PQ subspaces, where each call costs more than the math. In 4.1.0-rc.1 that made a 128 dim case using PQ with 2-float subspaces about 2x slower on native than on Panama. This fixes the causes instead of sending small vectors to Panama, so no dimension threshold is needed. It supersedes #791 and depends on #834.

  • PQ diversity scoring compares two codes straight from the codebooks, in one pass per comparison, for in-progress and saved PQ vectors alike. It replaces the per-subspace provider calls and the centroid-pair table, which grew with subspaces × 256² (17 MB at 128 subspaces) and was slow on Panama. The only new memory is one copy of the codebooks.

  • k-means++ initialization computes distances in Java, at every vector width, when the native update doesn't support the subspace size.

  • Native f32 dot, cosine and squared distance pass uncached heap segments, so freshly read vectors don't pay to create and cache a view.

  • The native vector view is cached without locking (from #791, by @r-devulap).
  • PQ train, encode and graph build time, 100k vectors (50k at 768–1024d, 30k at 1536d, 20k at 3072d), GNR (48 cores), main vs this PR, both with #834:

    | Dims, subspace width, similarity | native JDK 22 | native JDK 25 | Panama JDK 22 | Panama JDK 25 |
    |---|---|---|---|---|
    | 1, 1 float, Euclidean | 3.5 → 3.1 s | 3.1 → 3.1 s | 3.1 → 3.3 s | 3.5 → 3.2 s |
    | 8, 1 float, Euclidean | 2.5 → 2.2 s | 2.5 → 2.2 s | 2.1 → 2.1 s | 2.1 → 2.1 s |
    | 128, 1 float, Euclidean | 16.0 → 6.2 s | 15.1 → 6.2 s | 9.6 → 7.9 s | 8.8 → 5.8 s |
    | 128, 2 floats, Euclidean | 9.4 → 4.5 s | 8.7 → 5.6 s | 6.6 → 5.8 s | 5.1 → 4.7 s |
    | 128, 2 floats, cosine | 13.5 → 5.1 s | 12.6 → 6.3 s | 7.6 → 5.3 s | 6.2 → 4.5 s |
    | 128, 8 floats, Euclidean | 4.1 → 3.3 s | 3.6 → 3.2 s | 3.5 → 3.1 s | 3.1 → 2.7 s |
    | 768, 4 floats, dot product | 12.2 → 5.6 s | 11.6 → 5.9 s | 8.2 → 7.2 s | 5.4 → 4.9 s |
    | 1024, 8 floats, dot product | 9.8 → 4.5 s | 9.4 → 4.6 s | 7.0 → 7.1 s | 4.2 → 4.1 s |
    | 1536, 8 floats, dot product | 8.3 → 3.9 s | 8.1 → 4.1 s | 6.5 → 5.5 s | 4.2 → 3.8 s |
    | 3072, 8 floats, dot product | 11.1 → 5.0 s | 10.5 → 4.9 s | 7.8 → 5.9 s | 4.7 → 4.3 s |

    Data: SIFT for 1–128d, Cohere for 768–1024d, OpenAI for 1536–3072d. Across all 39 shapes tested (1–3072 dims, 1- to 32-float subspaces, all three similarity functions), this PR / main averages 0.70 on native and 0.89 on Panama; the cells near 1.0 are 1–16 dim builds of 2–3 s, within run-to-run noise.

    Ice Lake (8 cores) cells run so far agree (128d with 1-float subspaces: 123 s → 19 s native). Ice Lake (32 cores) results for the full set to follow.

    Diff: 334 lines (+250 / -84) across 4 files Reviewer: MarkWolters Review duration: 495m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 334 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%
    60%
    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.348
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #836"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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.2% (MEDIUM) · Higher = larger blast radius
    42.2%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 16.7% · Safe to merge
    16.7%