← Back to Pull requests

perf(blocksort): replace legacy quicksort with pure safe Rust DivSufSort #144

Open
gheffern opened this pull request with 295 lines diff across 3 files
View on GitHub
gheffern gheffern commented on Sep 02, 2026 17:14 UTC
Author

Replaces Julian Seward's 1996 ternary quicksort (mainSort) and fallback Larsson-Sadakane suffix sort (fallbackSort) with a clean 288-line Two-Stage Induced Suffix Sorting (DivSufSort) engine.

Key Highlights:

  • Linear-Time Induction: Induces sorted orders for S-type and L-type suffixes in two sequential passes without recursive call stacks.

  • Radix Pre-sorting: 2-byte radix bucket sort (65,536 buckets) for B* suffixes with AVX2-accelerated slice.cmp string comparison and 64-bit word-parallel LMS bitmask extraction (w & !prev_w).

  • Memory Safety: 100% safe Rust under #![forbid(unsafe_code)] with zero unsafe blocks.

  • Allocations: Zero heap allocations; operates strictly within existing EState arr1 (ptr) and arr2 (block + quadrant) buffers (no_std compliant).

  • Code Footprint: -2,084 net lines removed compared to the original 1996 C-style sorting implementation.
  • Benchmark Results (5-Iteration Interleaved A/B Benchmark):

  • Silesia Corpus Overall Compression: +20.3% speedup (20.46 -> 24.61 MB/s)

  • - nci (Chemical DB): +47.1% (15.04 -> 22.12 MB/s)
    - xml (Structured Markup): +44.8% (16.53 -> 23.93 MB/s)
    - webster (ASCII Text): +28.9% (20.28 -> 26.15 MB/s)
    - osdb (Database Binary): +16.1% (22.96 -> 26.65 MB/s)
    - samba (C Source Code): +15.3% (23.70 -> 27.33 MB/s)
    - mozilla (Executable Tar):+11.8% (23.14 -> 25.86 MB/s)
    - dickens (English Text): +11.6% (21.18 -> 23.63 MB/s)
    - ooffice (x86 Binary): +8.8% (22.16 -> 24.12 MB/s)
    - reymont (PDF Document): +7.0% (22.63 -> 24.21 MB/s)
    - sao (Binary Catalog): +5.6% (18.05 -> 19.05 MB/s)
    - x-ray (16-bit Sensor): -5.1% (20.55 -> 19.51 MB/s)
    - mr (16-bit MRI Scan): -10.5% (29.89 -> 26.75 MB/s)
  • NOAA NEXRAD Radar Archives:

  • - Compression Throughput: +2.3% (77.12 -> 78.91 MB/s)
    - Decompression Throughput: +5.5% (154.55 -> 163.02 MB/s)

    Test Suite & Verification:

  • Updated tests/compress-sample1-log.txt to remove legacy Seward -vvvv quicksort recursion traces (e.g. "qsort [0xXX, 0xYY]"), while all user-facing block CRCs, MTF stats, selector counts, and compression ratios remain bit-for-bit identical.

  • All 145 workspace tests in libbz2-rs-sys and bzip2-cli pass cleanly.
  • Code development and benchmarking harness execution for this PR were assisted by Gemini 3.8 Flash; all changes and results were reviewed by the author prior to submission.

    Diff: 295 lines (+221 / -74) across 3 files Reviewer: None requested Review duration: 134820m
    All Vouch review confidence checks passed
    Residual risk 0.34 = Change Risk (0.59) × (1 − Review Confidence (0.42)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.59 · 295 lines diff across 3 files
    0.59
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 10%
    42%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.340
    No Reviewer Assigned no_reviewer_assigned
    0.120
    Real PR Conversation Timeline
    1 comments
    "Review active on #144"
    general weight: 0.35
    Reviewers
    None requested
    Assignees
    gheffern gheffern
    Labels
    risk: low confidence: 42.2% 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: 59.0% (MEDIUM) · Higher = larger blast radius
    59.0%
    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: 42.2% · Lower = rushed or shallow review
    42.2%
    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: 34.1% · Safe to merge
    34.1%