← Back to Pull requests

Skip unnecessary SparkPlan.clone in GpuOverrideUtil.tryOverride [databricks] #17193

Open
unknown opened this pull request with 619 lines diff across 7 files
View on GitHub
unknown unknown commented on Nov 30, 2026 09:49 UTC
Author

Fixes #17192.
Contributes to #17191.

why

  • SparkPlan.clone() is time-consuming.

  • SparkPlan.clone() is not needed in the normal path:

  • - no throw
    - failOnError is true

    Description

    Skip SparkPlan.clone() in GpuOverrideUtil.tryOverride when failOnError is true and keep tryOverride only at the top-level Spark Rule.apply boundaries (GpuQueryStagePrepOverrides.apply, GpuOverrides.apply, and GpuTransitionOverrides.apply). This removes unnecessary full-tree TreeNode.clone() allocations and driver GC pressure during AQE query stage preparation and plan conversion while keeping rule error handling simple and stateless.

    In a local NDS SF100 A/B benchmark (Spark 3.5.6, Scala 2.12, JDK 17, one NVIDIA L4 GPU, local[16], 16 GiB driver/executor memory, 8 GiB pinned memory, six concurrent GPU tasks, AQE enabled, spark.rapids.sql.suppressPlanningFailure=false), this eliminates all 7,548 plan.clone() calls inside tryOverride per 103-query stream and reduces cumulative tryOverride time by 1.333 s (15.6%) per stream.

    | Metric, mean per complete stream | A: before | B: after | Change |
    | --- | ---: | ---: | ---: |
    | Cumulative tryOverride time, nested calls counted once | 8.536 s | 7.202 s | 1.333 s lower (15.6%) |
    | plan.clone() calls inside tryOverride | 7,548 | 0 | Eliminated in this configuration |
    | Sum of timed plan.clone() call durations | 2.039 s | 0 s | 2.039 s lower |
    | Whole-JVM GC pause time | 2.669 s | 2.428 s | 0.241 s lower (9.0%) |
    | Power Test Time | 344.5 s | 344.0 s | 0.5 s lower (0.15%) |
    | Sum of the 103 query times | 342.595 s | 342.697 s | 0.103 s higher (0.03%) |

    Benchmark notes:

  • A: pre-change tryOverride implementation from 730ebf0b50; B: benchmarked on an earlier prototype using the same failOnError=true zero-clone path (the final commit 45b809989 keeps the same zero-clone path and removes nested tryOverride checks altogether).

  • Each variant ran the complete 103-query stream three times in separate driver JVMs (A1, B1, B2, A2, A3, B3); Run 1 of each variant was excluded as warm-up and the table reports arithmetic means of Runs 2 and 3 (measured function times: A2 8.393 s, A3 8.678 s, B2 6.991 s, B3 7.414 s; saving 2.666 s across the two measured runs).

  • All 618 query executions reported Completed with GPU plans confirmed in event logs; this checks completion rather than CPU/GPU result parity. End-to-end SF100 runtime was essentially unchanged, and whole-JVM GC pause time includes work outside tryOverride.

  • Temporary System.nanoTime() instrumentation (not part of the PR) summed only outermost tryOverride invocations across the driver lifetime.
  • How it works:

  • Compute failOnError (TEST_CONF || !SUPPRESS_PLANNING_FAILURE) before cloning and store the backup in an Option[SparkPlan] (None when failOnError is true, Some(plan.clone()) only when failure suppression is enabled).

  • Move GpuOverrideUtil.tryOverride from GpuOverrides.applyWithContext up to GpuOverrides.apply and narrow applyWithContext to private[rapids], matching GpuOverrideUtil.withActiveSession placement so GpuQueryStagePrepOverrides.apply no longer invokes a nested tryOverride.

  • Removing the redundant inner tryOverride also ensures that when SUPPRESS_PLANNING_FAILURE=true and an inner override fails during AQE query stage preparation, the exception propagates to GpuQueryStagePrepOverrides.apply, skips DriverlessBroadcastStage.tagEligibleBuilds, and returns the clean untagged fallback clone rather than a partially tagged plan; under default failOnError=true, it also avoids duplicate ERROR logs.

  • Independent Databricks FileSourceScanExecMetaBase transition overrides keep their own tryOverride boundary.
  • Validation:

  • Static checks passed on 45b809989: git diff --check, scalastyle-all-modules, and python3 build/check_shim_compatibility.py review --base-ref origin/main --head-ref HEAD (PASS, 0 new findings and 0 base findings across 34 buildvers against origin/main ca4c1529d).

  • Local JDK 17 / Scala 2.12 / Spark 3.5.6 (-Dbuildver=356) tests build and GpuOverrideUtilSuite passed on 45b809989 (7/7 tests passed, 0 failures, 0 skipped).

  • Local Scala 2.13 compilation and full SF100 CPU/GPU result parity were not run locally (remaining for CI / premerge validation).
  • AI assistance was used to prepare this implementation, tests, and description.

    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: 619 lines (+464 / -155) across 7 files Reviewer: firestarman Review duration: 1213m
    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 · 619 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.385
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #17193"
    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%