← Back to Pull requests

perf: start the next local partition when a running one finishes #7693

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

Which issue does this PR close?

Part of #6499. Follow-up to #6883, found while benchmarking #7692.

Rationale for this change

A local query runs at most as many partitions at once as Spark runs tasks. Under the current scheduler, the next partition starts only when the first undelivered one is delivered. So a partition that finishes before its turn keeps its slot until it is delivered, and one slow partition leaves the slots behind it idle. Spark instead starts the next task whenever any task ends.

Range partitions are uniform, so this rarely shows with the ranges #6883 admits. Scan partitions are not: their splits differ in size and some read a file footer. With #7692, collecting a Parquet scan of 320 small partitions on local[8] took about 45% longer locally than with ordinary Comet. Per-partition timing of that case showed:

  • Planning and starting a partition took about 50 µs.

  • Running a partition took a median of 340 µs and up to 2.9 ms.

  • Finished partitions then waited a mean of 1.4 ms for delivery while keeping their slots.

  • On average only 2.9 of the 8 slots were busy.
  • What changes are included in this PR?

  • When a partition's task finishes, it drops the partition's stream, which releases its operators and their memory consumers, and wakes the reader so that another partition starts. The bound on running partitions now counts only partitions that have not finished. It still bounds how many partitions share the memory pool.

  • A finished partition waits for its turn holding the batches it has not delivered. Once as many partitions as may run at once are started and not delivered, another starts only while the undelivered batches total less than the read-ahead limit (spark.driver.maxResultSize). Without this bound, finished partitions could pile up their batches behind a slow one; in the experiment without it, up to 57 were waiting at once.

  • local-execution.md describes the new rule.
  • How are these changes tested?

  • New tests in native/local:

  • - a_partition_that_finishes_before_its_turn_gives_up_its_slot: while the first partition runs, each later partition that finishes drops its stream and lets the next one start.
    - finished_partitions_wait_for_their_turn_within_the_read_ahead_limit: with no read-ahead, a finished partition does not let a partition start beyond those that may run at once.
  • Two tests were rewritten because they asserted the old rule, that a partition starts only after the first is delivered: partition_order_runs_at_most_the_given_number_of_partitions and partition_order_follows_a_changing_running_limit. They now use partitions that run until the test lets them finish, so the bound is checked against running partitions. The first also replaces partitions_from_a_start_function_are_planned_as_they_start, since it plans its partitions with a start function.

  • Without the fix, a_partition_that_finishes_before_its_turn_gives_up_its_slot and the rewritten partition_order_runs_at_most_the_given_number_of_partitions fail. The read-ahead test passes either way, since it guards the bound this change adds.
  • Benchmark (collect, local[8], Apple M4 Max, release build, 8M rows in 64 Parquet files). The "before" build is #7692 and the "after" build is #7692 with this change; the two differ only in the native library, and the runs alternate between them to cancel drift on the machine. The selective filter cases come from three runs of each build at 30 iterations, in the order before/after, after/before, before/after. The other cases come from two full runs of each build at 10 iterations, in the order before/after, before/after. Times are averages in ms, before → after:

    | Case | Partitions | Spark | Comet | Comet local |
    |---|---|---|---|---|
    | Selective filter (8K rows returned) | 320 | 94 → 91 | 71 → 71 | 96 → 39 |
    | Selective filter (8K rows returned) | 8 | 65 → 63 | 33 → 33 | 31 → 31 |
    | All rows | 320 | 1158 → 1237 | 1097 → 1154 | 1108 → 1059 |
    | All rows | 8 | 1258 → 1330 | 1116 → 1199 | 1051 → 1227 |
    | All rows, half in one file | 8 | 1713 → 1674 | 1556 → 1426 | 1140 → 1056 |
    | Range, all rows | 8 | 527 → 510 | 534 → 490 | 423 → 449 |
    | Range, selective filter | 8 | 9 → 8 | 15 → 16 | 16 → 15 |

    Spark and ordinary Comet do not run the code this change touches, so their columns show the noise between runs. With many small partitions, local execution goes from about 35% slower than ordinary Comet to about 1.8x faster, and that case varied by less than 3 ms across runs. The other cases move within the noise that Spark and ordinary Comet show. The largest move is local execution of all rows over 8 partitions, but its single runs ranged from 964 to 1283 ms, and with 8 partitions all of them start at once, so this change does not alter their scheduling. CometLocalExecutionSuite also passes (35 tests) with this change applied on top of #7692.

    Diff: 616 lines (+462 / -154) across 7 files Reviewer: viirya Review duration: 15857m
    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 · 616 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 #7693"
    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%