← Back to Pull requests

Reduce Parquet cache heap pressure with smaller row-group records [databricks] #16633

Open
unknown opened this pull request with 615 lines diff across 7 files
View on GitHub
unknown unknown commented on Oct 27, 2026 14:10 UTC
Author

Fixes #16362.

Stacked on #16620.

Description

Large ParquetCachedBatch records can exhaust the JVM heap when Spark reloads cached partitions. Spark deserializes whole records and can retain a large number of them per task before checking its memory budget. The java serialization process can retain even more of them.

This change uses an 8 MiB uncompressed target for cache records while keeping larger GPU processing batches. We cap the row group size to 8 MiB, or so on both the CPU and the GPU when using PCBS. We then split the files apart by row group when writing and stitch them back together again for reading. This allows us to not lose much performance and still be fast.

The target is internal. No Spark changes or user configuration changes are required. The GPU target is soft because cuDF's page-fragment granularity can produce larger row groups.

Validation

Fresh Spark 3.5.5 build and tests:

  • 62 Scala tests and 13 Java tests passed.

  • PCBS cache integration tests: 625 passed, four existing large-data skips.

  • Default-cache regression: two passed.

  • Forced Parquet corpus tests: 84 passed, four expected failures, eight unexpected passes. Both footer modes exercised the file that previously exposed the dictionary-page regression.
  • Performance

    Spark cluster benchmarks used Spark 3.5.6, RAPIDS 26.12.0-SNAPSHOT, and SF3000 Parquet decimal datasets. Each configuration ran five separate Spark applications, with one measured iteration per query and no warmups.

    | Workload | Baseline mean | Patched mean | Runtime change |
    |---|---:|---:|---:|
    | TPC-DS | 235.0 s | 234.8 s | -0.09% |
    | TPC-H | 381.0 s | 382.0 s | +0.26% |

    Both overall differences were smaller than the observed run-to-run variation. All 1,270 query executions completed successfully. No individual query difference was statistically significant after Holm correction within each workload. Five applications per configuration provide limited sensitivity to small changes.

    Manual cache reproduction

    Local Spark 3.5.5 runs used an AMD Ryzen Threadripper PRO 5975WX (32 cores / 64 threads) but only 16 cores being used, a JVM heap of 50 GiB, off heap limited to 32 GiB and an NVIDIA RTX A6000 with 48 GiB GPU memory.

    The query is the same one that exposed the incorrect partitioning metadata fixed by #16620:

    import org.apache.spark.storage.StorageLevel
    import org.apache.spark.sql.functions._
    
    val data = spark.range(10000000000L)
      .selectExpr("id % 10 as k", "id as v")
      .persist(StorageLevel.MEMORY_AND_DISK)
    
    def run(): Unit = spark.time {
      data.groupBy("k").agg(max(col("v"))).orderBy("k").show()
    }
    
    run()                         // Fill the cache and read it.
    (1 to 5).foreach(_ => run())  // Read the populated cache.
    

    CPU/GPU selects whether RAPIDS execution is enabled. The serializers are Spark's DefaultCachedBatchSerializer and ParquetCachedBatchSerializer.

    All times below are milliseconds. "First" includes cache construction; the remaining columns read the populated cache.

    | JAR | Execution | Serializer | First | Read 1 | Read 2 | Read 3 | Read 4 | Read 5 |
    |---|---|---|---:|---:|---:|---:|---:|---:|
    | New | CPU | Default | 139,375 | 12,040 | 12,662 | 12,901 | 16,110 | 13,842 |
    | New | GPU | Default | Heap OOM | — | — | — | — | — |
    | New | CPU | PCBS | 322,471 | 190,511 | 191,508 | 191,235 | — | — |
    | New | GPU | PCBS | 33,786 | 5,823 | 5,624 | 5,725 | 5,726 | 5,387 |
    | Old | CPU | Default | 113,429 | 12,547 | 12,631 | 13,341 | 12,576 | 13,772 |
    | Old | GPU | Default | Heap OOM | — | — | — | — | — |
    | Old | CPU | PCBS | Heap OOM | — | — | — | — | — |
    | Old | GPU | PCBS | 30,992 | 6,373 | 6,194 | 5,865 | 5,958 | 6,193 |

    The patched CPU PCBS run completed where the old version exhausted the heap. CPU PCBS remains much slower than the default CPU cache. GPU PCBS read times were slightly lower in these runs, but the variation limits conclusions about small differences, particularly cache-fill times.

    These manual timings predate the correctness fix in #16620 and were not rerun with it. The final aggregation is small relative to the cache workload, but these measurements are performance observations, not correctness validation.

    The Heap OOM using the default serializer was not root caused, but is likely related to larger batch sizes and holding more data in memory to feed the serialization code, but I am not 100% sure on that.

    Implementation and tests were developed with AI assistance.

    Checklists

    Documentation

  • Updated for new or modified user-facing features or behaviors

  • No user-facing change
  • Testing

  • Added or modified tests to cover new code paths

  • Covered by existing tests

  • (Please provide the names of the existing tests in the PR description.)
  • Not required
  • Performance

  • Tests ran and results are added in the PR description

  • Issue filed with a link in the PR description

  • Not required
  • Diff: 615 lines (+461 / -154) across 7 files Reviewer: gerashegalov Review duration: 37789m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 615 lines diff across 7 files
    0.50
    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: 35%
    46%
    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.384
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #16633"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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.2% (MEDIUM) · Higher = larger blast radius
    50.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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 26.8% · Safe to merge
    26.8%