Keep Panama PQ and k-means distance loops in their own methods #843
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.43) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 379 lines diff across 4 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.355
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #843"
general
weight: 0.35
MarkWolters
On JDK 22 with the Panama provider, PQ training and encoding were sometimes much slower in a fresh JVM. The per-point and per-centroid distance loops for small subvectors (4 floats for 1024 dimensions at M=256) were sometimes compiled inside a large calling method, where C2 could not unbox one operand of the small-vector subtraction (
-XX:+PrintIntrinsicsprintsunbox failed), so each subtraction became a heap-allocating call. Three slow modes showed up:encodeAll): about 11x slower, 179-190 s instead of about 17 s, in 7 of 12 JVMs on Ice Lake (8 cores);Fix:
PanamaVectorUtilSupportnow implementstryClosestCentroidandtryUpdateKMeansDistances, as the native provider already does. Each one runs its whole loop in one method too large for C2 to inline into its callers (above FreqInlineSize, 325 bytecodes), so the loop is always compiled as its own unit. They use the same vector operations assquareDistanceandminInPlace, keep the first centroid on ties and check their inputs like the native versions. PQ encoding, k-means assignment and k-means++ initialization use them. Native is unchanged.Results, fresh JVMs, alternating order, 1M x 1024d cohere, M=256, times in seconds:
| Machine | JDK, provider | Phase | main | this PR |
|---|---|---|---|---|
| Ice Lake (8 cores) | 22 Panama | encode | 16.8 (fast JVMs), 179-190 (slow, 7 of 12) | 15.0-15.3, 0 of 9 slow |
| Ice Lake (8 cores) | 22 Panama | train (compute / refine) | 19.4 / 4.37 | 17.8 / 3.93 |
| Ice Lake (8 cores) | 25 Panama | encode | 13.9 | 12.6 |
| Ice Lake (8 cores) | 25 Panama | train (compute / refine) | 15.9 / 3.53 | 14.7 / 3.16 |
| GNR (48 cores) | 22 Panama | train compute | slow in 4 of 8 JVMs (61-67 s 15x, 11.8 s 3x) | 3.6-4.9, 0 of 24 slow |
| both | 22 / 25 native | all | unchanged | unchanged |
k-means++ initialization alone (GNR, 8 subspaces of 128k real subvectors, k=256, one thread, 4 JVMs each; mean of each JVM's steady-state median, ms; "before" runs the same loop as main):
| JDK | dims | before | this PR |
|---|---|---|---|
| 22 | 2 / 4 / 8 | 766 / 1078 / 1140 | 630 / 834 / 1107 |
| 25 | 2 / 4 / 8 | 839 / 1011 / 1166 | 754 / 824 / 981 |
The unchanged assignment step, timed in the same JVMs, is identical in both builds.
Anisotropic PQ encoding, which does not use these loops, showed no slow mode on main (5 of 5 JVMs within 0.5%).
Tests: new
PanamaClosestCentroidTestchecks both methods against the loops they replace (dimensions 0-65, 1-300 points or centroids, integer and Gaussian data), ties, non-finite values and input checks.KMeansInitializationTestnow expects Panama to handle every dimension. They pass with the PQ, k-means and closest-centroid tests on JDK 22 and 25 at 512-bit, AVX2 and 128-bit vector widths, Panama and native.