← Back to Pull requests

Compaction: eliminating disk scan and updating PQ retrain #691

Closed
unknown closed this pull request without merging on Aug 12, 2026 15:26 UTC
View on GitHub
unknown unknown commented on Jul 02, 2026 22:18 UTC
Author

What this PR does

Speeds up graph compaction (merging pre-built partition indexes into one) — 5.6–11.5× faster
cold
, at roughly the same recall. Five changes:

1. Eliminate the cold disk scan — computeLayerInfoFromSources called getNodes(0), which
seeks + reads every node record on disk just to count live nodes. Replaced with an in-memory
liveNodes.cardinality() popcount (no I/O). The big one on large datasets.
2. Warm-start PQ retrain — retrain the codebook via Lloyd's refinement from the existing
codebook instead of full k-means++ from scratch (far fewer passes, no recall loss).
3. Windowed streaming prefetch — sources are mmapped MADV_RANDOM, so bulk phases faulted one
page at a time. Now each phase (retrain sampling, code pre-encode, L0 batches) streams the exact
records it is about to read into the page cache first.
4. rerankK = searchTopK — the L0 cross-source search used a beam 2× the candidate budget; the
extra candidates are pruned by diversity selection anyway. Halving it cuts ~19% off L0 for
~0.006 recall.
5. Post-compaction refinement optional (default off) — it costs ~20–25% of compaction time and
contributes ~0 recall (a query-latency/navigability pass), so it is now opt-in.

The two structural fixes (1. scan elimination, 3. prefetch) remove the disk-bound overhead that
dominated cold compaction; 4./ 5. trim the remaining compute. Recall stays within ~0.006 of main.

main vs PR (perf-fix + prefetch): compaction time & recall

220g heap, -wi 1 -i 1 single fork ("cold" = warmup iteration),
drop_caches before each arm so both start disk-cold. Graph degree 32, beam width 100.
Recall is search@10 on the compacted graph.

  • main = b86a94c8 (stock)

  • PR = compaction-perf-fix @ 8324dd6d = disk-scan fix + warm-start retrain + streaming

  • prefetch + rerankK + refinement-off

    | Dataset | Workload | main cold | PR cold | Speedup | main recall | PR recall |
    |---|---|---|---|---|---|---|
    | cohere-1M | 2-TIERED | 2m58s | 26s | 6.8× | 0.6094 | 0.6116 |
    | cohere-1M | 2-UNIFORM | 2m58s | 19s | 9.4× | 0.6202 | 0.6145 |
    | cohere-1M | 4-UNIFORM | 3m09s | 27s | 7.0× | 0.6239 | 0.6230 |
    | cohere-10M | 2-TIERED | 27m09s | 2m44s | 9.9× | 0.5649 | 0.5631 |
    | cohere-10M | 2-UNIFORM | 27m00s | 2m46s | 9.8× | 0.5706 | 0.5648 |
    | cohere-10M | 4-UNIFORM | 29m24s | 4m34s | 6.4× | 0.5689 | 0.5668 |
    | cap-1M | 2-TIERED | 3m26s | 27s | 7.6× | 0.6646 | 0.6633 |
    | cap-1M | 2-UNIFORM | 3m15s | 26s | 7.5× | 0.6671 | 0.6630 |
    | cap-1M | 4-UNIFORM | 3m54s | 39s | 6.0× | 0.6706 | 0.6659 |
    | cap-6M | 2-TIERED | 17m15s | 2m11s | 7.9× | 0.6330 | 0.6277 |
    | cap-6M | 2-UNIFORM | 16m56s | 2m14s | 7.6× | 0.6360 | 0.6310 |
    | cap-6M | 4-UNIFORM | 18m36s | 3m20s | 5.6× | 0.6427 | 0.6356 |
    | dpr-gemma-1m | 2-TIERED | 2m48s | 19s | 8.8× | 0.7844 | 0.7781 |
    | dpr-gemma-1m | 2-UNIFORM | 2m44s | 17s | 9.6× | 0.7757 | 0.7769 |
    | dpr-gemma-1m | 4-UNIFORM | 2m55s | 24s | 7.3× | 0.7830 | 0.7846 |
    | dpr-gemma-10m | 2-TIERED | 25m41s | 2m14s | 11.5× | 0.6895 | 0.6868 |
    | dpr-gemma-10m | 2-UNIFORM | 26m01s | 2m20s | 11.2× | 0.6872 | 0.6852 |
    | dpr-gemma-10m | 4-UNIFORM | 26m57s | 3m42s | 7.3× | 0.7052 | 0.6961 |

    Takeaways

  • 5.6–11.5× faster cold compaction than main across every dataset.

  • Recall within ~0.006 of main
  • Diff: 431 lines (+323 / -108) across 5 files Reviewer: MarkWolters Review duration: 58627m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 431 lines diff across 5 files
    0.45
    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.363
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #691"
    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: 45.2% (MEDIUM) · Higher = larger blast radius
    45.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: 17.8% · Safe to merge
    17.8%