You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "mbutrovich (via GitHub)" <gi...@apache.org> on 2026/04/14 18:52:21 UTC
[PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
mbutrovich opened a new pull request, #21629:
URL: https://github.com/apache/datafusion/pull/21629
## Which issue does this PR close?
Partially addresses #21543. This is the ExternalSorter pipeline refactor from #21600, separated from the radix sort changes.
## Rationale for this change
ExternalSorter's merge path sorts each incoming batch individually (typically 8192 rows), then k-way merges all of them. At scale (TPC-H SF10, ~60M rows in lineitem), this produces ~7300 individually-sorted batches feeding the k-way merge with high fan-in.
## What changes are included in this PR?
### Coalesce-then-sort pipeline
Replaces ExternalSorter's buffer-then-sort architecture with a coalesce-then-sort pipeline:
- Incoming batches accumulate in a `BatchCoalescer` until `sort_coalesce_target_rows` (default 32768) is reached
- Each coalesced batch is sorted and chunked back to `batch_size`, producing fewer, larger sorted runs
- On memory pressure, sorted runs spill to disk (merged into one file when headroom is available, one file per run otherwise)
- At query completion, runs are k-way merged via the existing `StreamingMergeBuilder`
This reduces merge fan-in from ~7300 to ~1800 runs at SF10, which is the primary source of speedup.
### Spill strategy
- **With merge headroom** (`sort_spill_reservation_bytes > 0`): merge all runs into a single sorted stream before spilling to one file. Fewer files = lower fan-in for the final `MultiLevelMerge`.
- **Without headroom** (`sort_spill_reservation_bytes == 0`): spill each run as its own file. The multi-level merge handles low merge memory by reducing fan-in, so this no longer fails under tight memory budgets.
### Dead code removal
Sorted runs no longer require an in-memory merge before spilling. Removes `in_mem_sort_stream`, `sort_batch_stream`, `consume_and_spill_append`, `spill_finish`, `organize_stringview_arrays`, and `in_progress_spill_file`.
### Config changes
- New: `sort_coalesce_target_rows` (default 32768)
- Deprecated: `sort_in_place_threshold_bytes` (no longer read, `warn` attribute per API health policy)
## Are these changes tested?
- 4 new unit tests (coalescing, partial flush, per-run spill, merged spill)
- All 48 sort unit tests pass
- All sort fuzz, sort query fuzz, and spilling fuzz tests pass
- `information_schema.slt` updated for new config
## Are there any user-facing changes?
- New config `sort_coalesce_target_rows` (default 32768) controls the coalesce target before sorting
- `sort_in_place_threshold_bytes` is deprecated
- The pipeline is more memory-efficient (shrinks reservations after sorting) so some workloads may spill less frequently
- Sorts under tight memory budgets (`sort_spill_reservation_bytes` near zero) that previously failed now succeed via multi-level merge with reduced fan-in
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#discussion_r3088547619
##########
datafusion/physical-plan/src/sorts/sort.rs:
##########
@@ -323,56 +285,188 @@ impl ExternalSorter {
self.reserve_memory_for_batch_and_maybe_spill(&input)
.await?;
- self.in_mem_batches.push(input);
+ let coalescer = self
+ .coalescer
+ .as_mut()
+ .expect("coalescer must exist during insert phase");
+ coalescer
+ .push_batch(input)
+ .map_err(|e| DataFusionError::ArrowError(Box::new(e), None))?;
+
+ self.drain_completed_batches()?;
+
+ Ok(())
+ }
+
+ /// Drains completed (full) batches from the coalescer, sorts each,
+ /// and appends the sorted chunks to `sorted_runs`.
+ fn drain_completed_batches(&mut self) -> Result<()> {
+ // Collect completed batches first to avoid borrow conflict
+ let mut completed = vec![];
+ if let Some(coalescer) = self.coalescer.as_mut() {
+ while let Some(batch) = coalescer.next_completed_batch() {
+ completed.push(batch);
+ }
+ }
+ for batch in &completed {
+ self.sort_and_store_run(batch)?;
Review Comment:
Nice - I wonder if a part of the speedup comes from this (sorting batch immediately (while in CPU cache) instead of waiting to the end.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246972434
π€ Benchmark running (GKE) | [trigger](https://github.com/apache/datafusion/pull/21629#issuecomment-4246955834)
**Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB) | `Linux bench-c4246955834-1261-fd4rq 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux`
<details><summary>CPU Details (lscpu)</summary>
```
Architecture: aarch64
CPU op-mode(s): 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: ARM
Model name: Neoverse-V2
Model: 1
Thread(s) per core: 1
Core(s) per cluster: 16
Socket(s): -
Cluster(s): 1
Stepping: r0p1
BogoMIPS: 2000.00
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache: 1 MiB (16 instances)
L1i cache: 1 MiB (16 instances)
L2 cache: 32 MiB (16 instances)
L3 cache: 80 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Mitigation; CSV2, BHB
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Not affected
```
</details>
Comparing externalsorter (32a688271e2c9cb67b47454a2bc72f3cb926cfee) to e6b32fe (merge-base) [diff](https://github.com/apache/datafusion/compare/e6b32fe66b4e8e313ff79a9c45585d1a4bc2a19e..32a688271e2c9cb67b47454a2bc72f3cb926cfee) using: tpcds
Results will be posted here when complete
---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#discussion_r3088501037
##########
datafusion/physical-plan/src/sorts/sort.rs:
##########
@@ -95,116 +93,76 @@ impl ExternalSorterMetrics {
///
/// # Algorithm
///
-/// 1. get a non-empty new batch from input
+/// Incoming batches are coalesced via [`BatchCoalescer`] to
+/// `sort_coalesce_target_rows` (default 32768) before sorting. This
+/// reduces merge fan-in by producing fewer, larger sorted runs.
///
-/// 2. check with the memory manager there is sufficient space to
-/// buffer the batch in memory.
+/// Each coalesced batch is sorted immediately and stored as a
+/// pre-sorted run.
///
-/// 2.1 if memory is sufficient, buffer batch in memory, go to 1.
+/// 1. For each incoming batch:
+/// - Reserve memory (2x batch size). If reservation fails, flush
+/// the coalescer, spill all sorted runs to disk, then retry.
+/// - Push batch into the coalescer.
+/// - If the coalescer reached its target: sort the coalesced batch
+/// and store as a new sorted run.
///
-/// 2.2 if no more memory is available, sort all buffered batches and
-/// spill to file. buffer the next batch in memory, go to 1.
-///
-/// 3. when input is exhausted, merge all in memory batches and spills
-/// to get a total order.
+/// 2. When input is exhausted, merge all sorted runs (and any spill
+/// files) to produce a total order.
///
/// # When data fits in available memory
///
-/// If there is sufficient memory, data is sorted in memory to produce the output
+/// Sorted runs are merged in memory using a loser-tree k-way merge
+/// (via [`StreamingMergeBuilder`]).
///
/// ```text
-/// βββββββ
-/// β 2 β
-/// β 3 β
-/// β 1 ββ β β β β β β β β β
-/// β 4 β
-/// β 2 β β
-/// βββββββ βΌ
-/// βββββββ
-/// β 1 β In memory
-/// β 4 ββ β β β β ββΆ sort/merge β β β β ββΆ total sorted output
-/// β 1 β
-/// βββββββ β²
-/// ... β
-///
-/// βββββββ β
-/// β 4 β
-/// β 3 ββ β β β β β β β β β
-/// βββββββ
-///
-/// in_mem_batches
+/// ββββββββββββ ββββββββββββββ ββββββββ ββββββββββββββ
+/// β Incoming ββββββΆβ Batch ββββββΆβ Sort ββββββΆβ Sorted Run β
+/// β Batches β β Coalescer β β β β (in memory)β
+/// ββββββββββββ ββββββββββββββ ββββββββ βββββββ¬βββββββ
+/// β
+/// ββββββββββββββββ
+/// βΌ
+/// k-way merge (loser tree)
+/// β
+/// βΌ
+/// total sorted output
/// ```
///
/// # When data does not fit in available memory
///
-/// When memory is exhausted, data is first sorted and written to one
-/// or more spill files on disk:
-///
-/// ```text
-/// βββββββ .βββββββββββββββββ.
-/// β 2 β ( )
-/// β 3 β β`βββββββββββββββββ'β
-/// β 1 ββ β β β β β β β ββββββ β
-/// β 4 β β β β 1 ββ β
-/// β 2 β β β... ββ β
-/// βββββββ βΌ β β 4 ββ β β β β
-/// βββββββ β βββββββ 1 ββ β
-/// β 1 β In memory β ββββββ β ββ β
-/// β 4 ββ β βΆ sort/merge β β β β βΌ β β β β ββΆ ... ββ β
-/// β 1 β and write to file β β ββ β
-/// βββββββ β 4 ββ β
-/// ... β² β βββββββ β
-/// β β ββββββ β
-/// βββββββ β.βββββββββββββββββ.β
-/// β 4 β β ( )
-/// β 3 ββ β β β β β β `βββββββββββββββββ'
-/// βββββββ
-///
-/// in_mem_batches spills
-/// (file on disk in Arrow
-/// IPC format)
-/// ```
-///
-/// Once the input is completely read, the spill files are read and
-/// merged with any in memory batches to produce a single total sorted
-/// output:
+/// When memory is exhausted, sorted runs are spilled directly to disk
+/// (one spill file per run β no merge needed since runs are already
+/// sorted). `MultiLevelMergeBuilder` handles the final merge from disk
+/// with dynamic fan-in.
///
/// ```text
-/// .βββββββββββββββββ.
-/// ( )
-/// β`βββββββββββββββββ'β
-/// β ββββββ β
-/// β β 1 ββ β
-/// β β... ββ β β β β βββ β β β β β
-/// β β 4 ββ ββββββ β β
-/// β βββββββ β 1 ββ β βΌ
-/// β ββββββ β ββ β
-/// β β... ββ βββ β β βΆ merge β β ββΆ total sorted output
-/// β β ββ β
-/// β β 4 ββ β β²
-/// β βββββββ β β
-/// β ββββββ β
-/// β.βββββββββββββββββ.β β
-/// ( )
-/// `βββββββββββββββββ' β
-/// spills
+/// ββββββββββββ ββββββββββββββ ββββββββ ββββββββββββββ
+/// β Incoming ββββββΆβ Batch ββββββΆβ Sort ββββββΆβ Sorted Run β
Review Comment:
In the current approach, it would be worth it to "push down" the target batch size to the inner operation, so the output of the previous stage already is of the higher batch size instead of doing another copy.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich commented on code in PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#discussion_r3088742930
##########
datafusion/physical-plan/src/sorts/sort.rs:
##########
@@ -95,116 +93,76 @@ impl ExternalSorterMetrics {
///
/// # Algorithm
///
-/// 1. get a non-empty new batch from input
+/// Incoming batches are coalesced via [`BatchCoalescer`] to
+/// `sort_coalesce_target_rows` (default 32768) before sorting. This
+/// reduces merge fan-in by producing fewer, larger sorted runs.
///
-/// 2. check with the memory manager there is sufficient space to
-/// buffer the batch in memory.
+/// Each coalesced batch is sorted immediately and stored as a
+/// pre-sorted run.
///
-/// 2.1 if memory is sufficient, buffer batch in memory, go to 1.
+/// 1. For each incoming batch:
+/// - Reserve memory (2x batch size). If reservation fails, flush
+/// the coalescer, spill all sorted runs to disk, then retry.
+/// - Push batch into the coalescer.
+/// - If the coalescer reached its target: sort the coalesced batch
+/// and store as a new sorted run.
///
-/// 2.2 if no more memory is available, sort all buffered batches and
-/// spill to file. buffer the next batch in memory, go to 1.
-///
-/// 3. when input is exhausted, merge all in memory batches and spills
-/// to get a total order.
+/// 2. When input is exhausted, merge all sorted runs (and any spill
+/// files) to produce a total order.
///
/// # When data fits in available memory
///
-/// If there is sufficient memory, data is sorted in memory to produce the output
+/// Sorted runs are merged in memory using a loser-tree k-way merge
+/// (via [`StreamingMergeBuilder`]).
///
/// ```text
-/// βββββββ
-/// β 2 β
-/// β 3 β
-/// β 1 ββ β β β β β β β β β
-/// β 4 β
-/// β 2 β β
-/// βββββββ βΌ
-/// βββββββ
-/// β 1 β In memory
-/// β 4 ββ β β β β ββΆ sort/merge β β β β ββΆ total sorted output
-/// β 1 β
-/// βββββββ β²
-/// ... β
-///
-/// βββββββ β
-/// β 4 β
-/// β 3 ββ β β β β β β β β β
-/// βββββββ
-///
-/// in_mem_batches
+/// ββββββββββββ ββββββββββββββ ββββββββ ββββββββββββββ
+/// β Incoming ββββββΆβ Batch ββββββΆβ Sort ββββββΆβ Sorted Run β
+/// β Batches β β Coalescer β β β β (in memory)β
+/// ββββββββββββ ββββββββββββββ ββββββββ βββββββ¬βββββββ
+/// β
+/// ββββββββββββββββ
+/// βΌ
+/// k-way merge (loser tree)
+/// β
+/// βΌ
+/// total sorted output
/// ```
///
/// # When data does not fit in available memory
///
-/// When memory is exhausted, data is first sorted and written to one
-/// or more spill files on disk:
-///
-/// ```text
-/// βββββββ .βββββββββββββββββ.
-/// β 2 β ( )
-/// β 3 β β`βββββββββββββββββ'β
-/// β 1 ββ β β β β β β β ββββββ β
-/// β 4 β β β β 1 ββ β
-/// β 2 β β β... ββ β
-/// βββββββ βΌ β β 4 ββ β β β β
-/// βββββββ β βββββββ 1 ββ β
-/// β 1 β In memory β ββββββ β ββ β
-/// β 4 ββ β βΆ sort/merge β β β β βΌ β β β β ββΆ ... ββ β
-/// β 1 β and write to file β β ββ β
-/// βββββββ β 4 ββ β
-/// ... β² β βββββββ β
-/// β β ββββββ β
-/// βββββββ β.βββββββββββββββββ.β
-/// β 4 β β ( )
-/// β 3 ββ β β β β β β `βββββββββββββββββ'
-/// βββββββ
-///
-/// in_mem_batches spills
-/// (file on disk in Arrow
-/// IPC format)
-/// ```
-///
-/// Once the input is completely read, the spill files are read and
-/// merged with any in memory batches to produce a single total sorted
-/// output:
+/// When memory is exhausted, sorted runs are spilled directly to disk
+/// (one spill file per run β no merge needed since runs are already
+/// sorted). `MultiLevelMergeBuilder` handles the final merge from disk
+/// with dynamic fan-in.
///
/// ```text
-/// .βββββββββββββββββ.
-/// ( )
-/// β`βββββββββββββββββ'β
-/// β ββββββ β
-/// β β 1 ββ β
-/// β β... ββ β β β β βββ β β β β β
-/// β β 4 ββ ββββββ β β
-/// β βββββββ β 1 ββ β βΌ
-/// β ββββββ β ββ β
-/// β β... ββ βββ β β βΆ merge β β ββΆ total sorted output
-/// β β ββ β
-/// β β 4 ββ β β²
-/// β βββββββ β β
-/// β ββββββ β
-/// β.βββββββββββββββββ.β β
-/// ( )
-/// `βββββββββββββββββ' β
-/// spills
+/// ββββββββββββ ββββββββββββββ ββββββββ ββββββββββββββ
+/// β Incoming ββββββΆβ Batch ββββββΆβ Sort ββββββΆβ Sorted Run β
Review Comment:
@andygrove and I have been discussing this in the context of Comet, where for some Spark stages that get translated to native plans we'd possibly want to set different target batch sizes. What you're proposing sounds even more granular, where individual operators could potentially advertise an ideal input batch size, though this could get complicated fast based on schema. Maybe some sort of trait on operators to advertise when they want larger batch sizes, and the optimizer could figure out what that target should be?
Regardless, a general solution seems out of scope for this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4257501222
Would be nice to see results in `sort` bench / `sort_tpch` etc. to see if we didnt have any regressions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4261195635
## Benchmark Analysis: `externalsorter` vs `main`
Ran `cargo bench --bench sort -p datafusion` on both branches.
### Improvements (numeric, StringView, single-column string)
| Benchmark | externalsorter | main | Speedup |
|:---|---:|---:|---:|
| sort i64 100k | 2.40 ms | 3.88 ms | 1.61x |
| sort f64 100k | 2.61 ms | 3.94 ms | 1.51x |
| sort merge i64 1M | 26.6 ms | 38.5 ms | 1.45x |
| sort i64 1M | 33.8 ms | 45.5 ms | 1.35x |
| sort f64 1M | 35.8 ms | 46.4 ms | 1.30x |
| sort utf8 high cardinality 1M | 59.7 ms | 74.0 ms | 1.24x |
| sort utf8 view tuple 1M | 8.1 ms | 9.1 ms | 1.13x |
### Regressions (multi-column StringArray and Dictionary)
| Benchmark | externalsorter | main | Slowdown |
|:---|---:|---:|---:|
| sort utf8 tuple 100k (3x StringArray) | 23.7 ms | 9.5 ms | 2.5x |
| sort utf8 tuple 1M (3x StringArray) | 272 ms | 111 ms | 2.5x |
| sort mixed dictionary tuple 1M (3x dict + i64) | 283 ms | 108 ms | 2.6x |
| sort utf8 dictionary tuple 1M (3x dict) | 92.4 ms | 78.5 ms | 1.18x |
### Root cause
The coalesce-then-sort pipeline does: coalesce (copy all column data) -> `lexsort_to_indices` -> `take` (random-access scatter-gather) -> chunk back to `batch_size`. With multiple StringArray or Dictionary columns at 32K rows, the `take` scatter-gathers across ~1.9 MB of string heap data, exceeding L2 cache.
Schemas that **don't** regress help pinpoint the cause:
- **Single StringArray** (e.g. `sort utf8 high cardinality 1M`, +1.24x): one ~640KB string buffer fits in L2 during `take`
- **StringViewArray** (e.g. `sort utf8 view tuple 1M`, +1.13x): `take` copies fixed-size 16-byte view structs β no heap random access
- **Fixed-width** (i64, f64): coalesce is memcpy, `take` is sequential β all cache-friendly
### Benchmark batch size
The sort benchmark uses `BATCH_SIZE = 1024`, while DataFusion's default is 8192. This makes the coalesce expand 32x (1024 -> 32768) instead of 4x (8192 -> 32768), amplifying the copy cost. Small batches are a valid scenario though β filters, joins, and sources with pushdown can all produce sub-8192 batches.
### Proposed fix
Arrow's `BatchCoalescer` has a `with_biggest_coalesce_batch_size(Some(limit))` option: batches larger than `limit` bypass coalescing and pass through directly. For schemas with non-view variable-length columns (StringArray, BinaryArray, DictionaryArray), set this to `batch_size`. This way:
- Full-size batches (>= 8192 rows) pass through without string copying β sorted directly as individual runs
- Small batches still coalesce to reduce fan-in
- Fixed-width and StringView schemas keep the full 32K coalesce target unchanged
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246583949
π€ Benchmark running (GKE) | [trigger](https://github.com/apache/datafusion/pull/21629#issuecomment-4246572576)
**Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB) | `Linux bench-c4246572576-1254-cr9dg 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux`
<details><summary>CPU Details (lscpu)</summary>
```
Architecture: aarch64
CPU op-mode(s): 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: ARM
Model name: Neoverse-V2
Model: 1
Thread(s) per core: 1
Core(s) per cluster: 16
Socket(s): -
Cluster(s): 1
Stepping: r0p1
BogoMIPS: 2000.00
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache: 1 MiB (16 instances)
L1i cache: 1 MiB (16 instances)
L2 cache: 32 MiB (16 instances)
L3 cache: 80 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Mitigation; CSV2, BHB
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Not affected
```
</details>
Comparing externalsorter (32a688271e2c9cb67b47454a2bc72f3cb926cfee) to e6b32fe (merge-base) [diff](https://github.com/apache/datafusion/compare/e6b32fe66b4e8e313ff79a9c45585d1a4bc2a19e..32a688271e2c9cb67b47454a2bc72f3cb926cfee) using: tpch10
Results will be posted here when complete
---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246979942
π€ Benchmark completed (GKE) | [trigger](https://github.com/apache/datafusion/pull/21629#issuecomment-4246870829)
**Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB)
<details><summary>CPU Details (lscpu)</summary>
```
Architecture: aarch64
CPU op-mode(s): 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: ARM
Model name: Neoverse-V2
Model: 1
Thread(s) per core: 1
Core(s) per cluster: 16
Socket(s): -
Cluster(s): 1
Stepping: r0p1
BogoMIPS: 2000.00
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache: 1 MiB (16 instances)
L1i cache: 1 MiB (16 instances)
L2 cache: 32 MiB (16 instances)
L3 cache: 80 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Mitigation; CSV2, BHB
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Not affected
```
</details>
<details><summary>Details</summary>
<p>
```
Comparing HEAD and externalsorter
--------------------
Benchmark tpcds_sf1.json
--------------------
βββββββββββββ³βββββββββββββββββββββββββββββββββββββββββββ³βββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββββ
β Query β HEAD β externalsorter β Change β
β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β QQuery 1 β 7.01 / 7.45 Β±0.76 / 8.97 ms β 6.86 / 7.33 Β±0.76 / 8.86 ms β no change β
β QQuery 2 β 143.89 / 145.42 Β±1.02 / 146.77 ms β 144.14 / 144.53 Β±0.34 / 144.98 ms β no change β
β QQuery 3 β 113.87 / 114.65 Β±0.88 / 116.36 ms β 112.84 / 113.44 Β±0.33 / 113.81 ms β no change β
β QQuery 4 β 1401.22 / 1414.73 Β±10.96 / 1426.97 ms β 1375.61 / 1415.42 Β±34.40 / 1474.26 ms β no change β
β QQuery 5 β 172.81 / 173.85 Β±0.86 / 175.03 ms β 171.04 / 173.32 Β±1.69 / 176.20 ms β no change β
β QQuery 6 β 849.72 / 867.23 Β±21.92 / 910.12 ms β 844.09 / 868.62 Β±14.87 / 886.90 ms β no change β
β QQuery 7 β 342.84 / 346.08 Β±2.21 / 348.99 ms β 340.64 / 346.49 Β±3.18 / 349.42 ms β no change β
β QQuery 8 β 114.66 / 118.26 Β±2.55 / 121.27 ms β 115.19 / 117.12 Β±1.25 / 119.03 ms β no change β
β QQuery 9 β 102.77 / 106.97 Β±2.19 / 108.84 ms β 101.33 / 104.25 Β±2.34 / 107.23 ms β no change β
β QQuery 10 β 106.87 / 108.20 Β±1.11 / 109.99 ms β 106.29 / 107.45 Β±0.83 / 108.26 ms β no change β
β QQuery 11 β 979.18 / 996.03 Β±12.64 / 1016.91 ms β 978.22 / 994.80 Β±11.45 / 1005.19 ms β no change β
β QQuery 12 β 45.78 / 46.90 Β±0.77 / 47.81 ms β 46.11 / 46.62 Β±0.56 / 47.52 ms β no change β
β QQuery 13 β 400.14 / 406.86 Β±4.06 / 411.44 ms β 399.86 / 401.85 Β±1.71 / 404.03 ms β no change β
β QQuery 14 β 1005.02 / 1010.73 Β±4.14 / 1016.44 ms β 1006.11 / 1017.87 Β±5.97 / 1022.22 ms β no change β
β QQuery 15 β 15.86 / 16.77 Β±0.80 / 18.09 ms β 17.18 / 17.56 Β±0.44 / 18.16 ms β no change β
β QQuery 16 β 7.52 / 8.15 Β±0.80 / 9.71 ms β 7.75 / 8.30 Β±0.76 / 9.80 ms β no change β
β QQuery 17 β 229.36 / 232.27 Β±1.73 / 234.46 ms β 228.99 / 231.71 Β±1.82 / 233.57 ms β no change β
β QQuery 18 β 128.73 / 130.55 Β±1.18 / 132.14 ms β 127.41 / 128.06 Β±0.35 / 128.37 ms β no change β
β QQuery 19 β 157.04 / 158.82 Β±1.07 / 159.90 ms β 154.25 / 156.86 Β±1.97 / 159.56 ms β no change β
β QQuery 20 β 14.36 / 15.46 Β±1.21 / 17.78 ms β 14.30 / 14.43 Β±0.11 / 14.58 ms β +1.07x faster β
β QQuery 21 β 20.67 / 21.23 Β±0.67 / 22.52 ms β 19.34 / 20.15 Β±0.97 / 22.07 ms β +1.05x faster β
β QQuery 22 β 497.76 / 508.34 Β±13.13 / 533.70 ms β 495.94 / 501.46 Β±3.52 / 506.77 ms β no change β
β QQuery 23 β 889.24 / 907.21 Β±14.23 / 925.97 ms β 893.40 / 899.61 Β±4.57 / 906.89 ms β no change β
β QQuery 24 β 387.44 / 388.95 Β±1.42 / 390.89 ms β 386.47 / 389.37 Β±2.64 / 393.78 ms β no change β
β QQuery 25 β 343.17 / 344.96 Β±1.89 / 348.14 ms β 342.38 / 345.21 Β±2.02 / 348.12 ms β no change β
β QQuery 26 β 81.18 / 82.14 Β±0.92 / 83.78 ms β 81.84 / 82.45 Β±0.50 / 83.05 ms β no change β
β QQuery 27 β 7.11 / 7.80 Β±0.57 / 8.57 ms β 6.95 / 7.12 Β±0.20 / 7.52 ms β +1.09x faster β
β QQuery 28 β 149.19 / 151.22 Β±2.00 / 153.66 ms β 148.65 / 149.84 Β±1.42 / 152.26 ms β no change β
β QQuery 29 β 284.41 / 285.07 Β±0.66 / 286.29 ms β 281.94 / 284.39 Β±2.14 / 288.36 ms β no change β
β QQuery 30 β 44.81 / 45.93 Β±0.71 / 46.81 ms β 43.96 / 46.06 Β±2.08 / 49.33 ms β no change β
β QQuery 31 β 171.15 / 172.97 Β±1.43 / 174.91 ms β 172.65 / 173.79 Β±1.63 / 176.88 ms β no change β
β QQuery 32 β 56.82 / 58.38 Β±1.24 / 60.33 ms β 56.43 / 57.76 Β±1.03 / 58.88 ms β no change β
β QQuery 33 β 142.10 / 144.90 Β±2.15 / 147.95 ms β 139.34 / 141.40 Β±1.16 / 142.92 ms β no change β
β QQuery 34 β 7.35 / 8.12 Β±0.68 / 9.21 ms β 7.06 / 7.24 Β±0.21 / 7.64 ms β +1.12x faster β
β QQuery 35 β 106.90 / 110.45 Β±1.85 / 112.09 ms β 109.46 / 110.15 Β±0.43 / 110.71 ms β no change β
β QQuery 36 β 6.83 / 7.03 Β±0.13 / 7.24 ms β 6.72 / 7.01 Β±0.29 / 7.51 ms β no change β
β QQuery 37 β 8.46 / 9.24 Β±0.74 / 10.59 ms β 8.33 / 8.96 Β±0.50 / 9.80 ms β no change β
β QQuery 38 β 84.81 / 87.66 Β±3.86 / 95.24 ms β 85.27 / 89.04 Β±3.62 / 95.67 ms β no change β
β QQuery 39 β 129.76 / 131.65 Β±1.67 / 134.15 ms β 124.77 / 129.08 Β±2.58 / 132.06 ms β no change β
β QQuery 40 β 109.28 / 117.12 Β±8.65 / 130.76 ms β 110.88 / 117.60 Β±6.08 / 127.82 ms β no change β
β QQuery 41 β 15.02 / 16.29 Β±1.00 / 17.64 ms β 15.41 / 17.04 Β±1.11 / 18.27 ms β no change β
β QQuery 42 β 107.23 / 108.91 Β±1.34 / 110.82 ms β 107.51 / 109.06 Β±1.09 / 110.48 ms β no change β
β QQuery 43 β 5.94 / 6.37 Β±0.39 / 6.96 ms β 6.18 / 6.25 Β±0.08 / 6.40 ms β no change β
β QQuery 44 β 11.99 / 12.97 Β±0.82 / 14.26 ms β 11.84 / 12.31 Β±0.31 / 12.80 ms β +1.05x faster β
β QQuery 45 β 50.23 / 51.40 Β±0.97 / 53.18 ms β 51.56 / 52.44 Β±0.61 / 53.44 ms β no change β
β QQuery 46 β 8.77 / 8.98 Β±0.27 / 9.50 ms β 8.65 / 9.04 Β±0.27 / 9.34 ms β no change β
β QQuery 47 β 736.62 / 740.19 Β±2.82 / 744.07 ms β 740.07 / 752.22 Β±8.62 / 765.87 ms β no change β
β QQuery 48 β 284.59 / 290.01 Β±4.10 / 293.96 ms β 293.83 / 297.49 Β±2.75 / 300.53 ms β no change β
β QQuery 49 β 253.71 / 255.10 Β±2.14 / 259.35 ms β 255.25 / 258.21 Β±3.43 / 264.52 ms β no change β
β QQuery 50 β 223.04 / 230.46 Β±4.08 / 235.47 ms β 226.51 / 231.44 Β±4.77 / 240.07 ms β no change β
β QQuery 51 β 176.96 / 182.13 Β±3.82 / 187.71 ms β 176.29 / 180.81 Β±2.47 / 183.74 ms β no change β
β QQuery 52 β 107.33 / 109.46 Β±1.41 / 111.41 ms β 107.57 / 108.99 Β±1.05 / 110.55 ms β no change β
β QQuery 53 β 102.43 / 103.30 Β±0.65 / 104.40 ms β 103.62 / 105.36 Β±1.23 / 106.72 ms β no change β
β QQuery 54 β 146.18 / 148.23 Β±1.27 / 149.58 ms β 148.37 / 149.35 Β±0.63 / 150.05 ms β no change β
β QQuery 55 β 107.79 / 108.25 Β±0.41 / 108.94 ms β 107.48 / 109.60 Β±1.64 / 111.60 ms β no change β
β QQuery 56 β 141.15 / 144.06 Β±2.28 / 148.09 ms β 143.45 / 143.90 Β±0.33 / 144.31 ms β no change β
β QQuery 57 β 172.66 / 176.77 Β±2.31 / 179.17 ms β 177.37 / 180.72 Β±1.82 / 182.84 ms β no change β
β QQuery 58 β 291.45 / 299.39 Β±7.65 / 312.42 ms β 292.57 / 302.23 Β±6.72 / 310.96 ms β no change β
β QQuery 59 β 196.29 / 199.92 Β±2.07 / 201.76 ms β 197.31 / 199.26 Β±1.37 / 201.47 ms β no change β
β QQuery 60 β 144.44 / 146.41 Β±1.68 / 148.87 ms β 143.09 / 144.42 Β±1.24 / 146.47 ms β no change β
β QQuery 61 β 13.83 / 13.98 Β±0.10 / 14.11 ms β 13.63 / 13.93 Β±0.26 / 14.30 ms β no change β
β QQuery 62 β 919.73 / 942.68 Β±18.45 / 972.49 ms β 932.03 / 955.86 Β±13.20 / 971.95 ms β no change β
β QQuery 63 β 104.37 / 106.07 Β±1.62 / 108.70 ms β 103.59 / 106.97 Β±2.04 / 109.72 ms β no change β
β QQuery 64 β 697.29 / 699.87 Β±3.89 / 707.59 ms β 691.38 / 695.19 Β±4.92 / 704.88 ms β no change β
β QQuery 65 β 257.00 / 261.25 Β±3.46 / 264.97 ms β 258.16 / 261.87 Β±2.10 / 264.22 ms β no change β
β QQuery 66 β 259.51 / 268.10 Β±7.69 / 278.86 ms β 250.70 / 262.91 Β±7.62 / 271.65 ms β no change β
β QQuery 67 β 319.33 / 321.91 Β±1.79 / 324.36 ms β 336.27 / 343.89 Β±5.52 / 351.61 ms β 1.07x slower β
β QQuery 68 β 9.10 / 9.97 Β±0.98 / 11.30 ms β 9.39 / 10.47 Β±0.96 / 11.84 ms β 1.05x slower β
β QQuery 69 β 104.04 / 104.66 Β±0.34 / 105.00 ms β 102.68 / 104.22 Β±1.23 / 105.80 ms β no change β
β QQuery 70 β 340.83 / 355.26 Β±16.33 / 385.41 ms β 351.12 / 353.81 Β±4.33 / 362.46 ms β no change β
β QQuery 71 β 133.55 / 137.03 Β±1.90 / 139.00 ms β 136.24 / 139.01 Β±1.97 / 141.07 ms β no change β
β QQuery 72 β 620.87 / 628.24 Β±5.11 / 635.42 ms β 609.20 / 627.19 Β±9.93 / 635.88 ms β no change β
β QQuery 73 β 7.29 / 8.88 Β±1.62 / 11.43 ms β 6.97 / 7.94 Β±0.86 / 9.20 ms β +1.12x faster β
β QQuery 74 β 627.03 / 629.77 Β±3.36 / 635.82 ms β 616.96 / 624.80 Β±7.29 / 637.86 ms β no change β
β QQuery 75 β 277.81 / 279.73 Β±1.19 / 280.99 ms β 279.22 / 281.63 Β±2.30 / 285.95 ms β no change β
β QQuery 76 β 133.72 / 135.05 Β±1.27 / 137.09 ms β 131.85 / 132.92 Β±0.81 / 134.16 ms β no change β
β QQuery 77 β 187.78 / 189.97 Β±1.77 / 192.13 ms β 187.66 / 189.23 Β±1.01 / 190.37 ms β no change β
β QQuery 78 β 346.27 / 349.32 Β±3.11 / 354.42 ms β 344.17 / 354.63 Β±14.98 / 384.41 ms β no change β
β QQuery 79 β 236.11 / 238.19 Β±2.16 / 241.93 ms β 237.78 / 240.48 Β±1.71 / 242.15 ms β no change β
β QQuery 80 β 324.53 / 328.03 Β±1.94 / 330.48 ms β 321.56 / 323.84 Β±2.94 / 329.54 ms β no change β
β QQuery 81 β 26.42 / 27.84 Β±0.89 / 28.95 ms β 26.32 / 27.51 Β±1.28 / 29.55 ms β no change β
β QQuery 82 β 197.20 / 199.01 Β±1.20 / 200.43 ms β 198.05 / 200.79 Β±2.39 / 204.17 ms β no change β
β QQuery 83 β 39.67 / 40.59 Β±0.87 / 41.89 ms β 39.70 / 40.73 Β±0.99 / 42.43 ms β no change β
β QQuery 84 β 48.91 / 50.07 Β±0.91 / 51.07 ms β 48.96 / 49.27 Β±0.30 / 49.65 ms β no change β
β QQuery 85 β 149.95 / 151.33 Β±0.89 / 152.43 ms β 148.70 / 151.71 Β±2.59 / 156.46 ms β no change β
β QQuery 86 β 38.87 / 39.91 Β±0.74 / 41.18 ms β 40.86 / 41.24 Β±0.48 / 42.14 ms β no change β
β QQuery 87 β 84.97 / 88.11 Β±3.14 / 93.62 ms β 88.48 / 93.26 Β±2.59 / 96.23 ms β 1.06x slower β
β QQuery 88 β 101.32 / 102.36 Β±0.84 / 103.90 ms β 102.27 / 107.65 Β±8.60 / 124.69 ms β 1.05x slower β
β QQuery 89 β 119.17 / 119.71 Β±0.53 / 120.62 ms β 120.50 / 122.28 Β±0.91 / 122.95 ms β no change β
β QQuery 90 β 23.99 / 24.45 Β±0.52 / 25.25 ms β 24.54 / 24.99 Β±0.37 / 25.57 ms β no change β
β QQuery 91 β 62.95 / 64.64 Β±1.10 / 66.08 ms β 64.97 / 65.48 Β±0.76 / 66.98 ms β no change β
β QQuery 92 β 58.76 / 59.16 Β±0.38 / 59.77 ms β 58.20 / 59.17 Β±0.82 / 60.20 ms β no change β
β QQuery 93 β 187.34 / 188.83 Β±0.90 / 189.54 ms β 191.90 / 193.75 Β±0.97 / 194.61 ms β no change β
β QQuery 94 β 62.13 / 62.99 Β±0.73 / 64.29 ms β 61.72 / 63.42 Β±1.25 / 65.24 ms β no change β
β QQuery 95 β 128.77 / 129.85 Β±1.10 / 131.80 ms β 128.83 / 130.56 Β±0.88 / 131.22 ms β no change β
β QQuery 96 β 72.12 / 74.37 Β±1.31 / 75.93 ms β 72.29 / 74.77 Β±2.10 / 78.50 ms β no change β
β QQuery 97 β 126.64 / 128.37 Β±1.42 / 130.62 ms β 128.40 / 130.65 Β±1.52 / 133.03 ms β no change β
β QQuery 98 β 153.54 / 157.50 Β±2.41 / 160.45 ms β 152.50 / 157.79 Β±3.02 / 160.62 ms β no change β
β QQuery 99 β 10778.07 / 10851.32 Β±50.12 / 10897.00 ms β 10813.12 / 10846.76 Β±31.71 / 10892.84 ms β no change β
βββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββ
βββββββββββββββββββββββββββββββββ³βββββββββββββ
β Benchmark Summary β β
β‘βββββββββββββββββββββββββββββββββββββββββββββ©
β Total Time (HEAD) β 31922.73ms β
β Total Time (externalsorter) β 31966.45ms β
β Average Time (HEAD) β 322.45ms β
β Average Time (externalsorter) β 322.89ms β
β Queries Faster β 6 β
β Queries Slower β 4 β
β Queries with No Change β 89 β
β Queries with Failure β 0 β
βββββββββββββββββββββββββββββββββ΄βββββββββββββ
```
</p>
</details>
<details><summary>Resource Usage</summary>
**tpcds β base (merge-base)**
| Metric | Value |
|--------|-------|
| Wall time | 160.0s |
| Peak memory | 5.8 GiB |
| Avg memory | 4.7 GiB |
| CPU user | 264.3s |
| CPU sys | 16.7s |
| Peak spill | 0 B |
**tpcds β branch**
| Metric | Value |
|--------|-------|
| Wall time | 160.1s |
| Peak memory | 5.1 GiB |
| Avg memory | 4.4 GiB |
| CPU user | 264.4s |
| CPU sys | 17.4s |
| Peak spill | 0 B |
</details>
---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246757710
I also opened a new PR that scales our existing sort benchmark to larger numbers: https://github.com/apache/datafusion/pull/21630
In theory we should merge that first, then run the sort benchmark against `main` after that is in. In the meantime I can run that locally and update with results.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246726760
Wooh, nice results
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246572576
run benchmark tpch10
```
env:
PREFER_HASH_JOIN: false
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246681907
π€ Benchmark completed (GKE) | [trigger](https://github.com/apache/datafusion/pull/21629#issuecomment-4246572576)
**Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB)
<details><summary>CPU Details (lscpu)</summary>
```
Architecture: aarch64
CPU op-mode(s): 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: ARM
Model name: Neoverse-V2
Model: 1
Thread(s) per core: 1
Core(s) per cluster: 16
Socket(s): -
Cluster(s): 1
Stepping: r0p1
BogoMIPS: 2000.00
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache: 1 MiB (16 instances)
L1i cache: 1 MiB (16 instances)
L2 cache: 32 MiB (16 instances)
L3 cache: 80 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Mitigation; CSV2, BHB
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Not affected
```
</details>
<details><summary>Details</summary>
<p>
```
Comparing HEAD and externalsorter
--------------------
Benchmark tpch_sf10.json
--------------------
βββββββββββββ³βββββββββββββββββββββββββββββββββββββββββ³βββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββββ
β Query β HEAD β externalsorter β Change β
β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β QQuery 1 β 369.64 / 376.08 Β±5.23 / 382.99 ms β 369.46 / 374.50 Β±3.39 / 378.57 ms β no change β
β QQuery 2 β 485.14 / 497.33 Β±11.38 / 515.80 ms β 438.26 / 446.15 Β±6.06 / 456.09 ms β +1.11x faster β
β QQuery 3 β 589.99 / 660.25 Β±37.61 / 696.76 ms β 514.23 / 531.74 Β±9.61 / 542.05 ms β +1.24x faster β
β QQuery 4 β 407.91 / 473.96 Β±36.86 / 509.58 ms β 334.86 / 341.61 Β±6.01 / 352.42 ms β +1.39x faster β
β QQuery 5 β 1118.92 / 1156.54 Β±22.75 / 1181.28 ms β 1025.31 / 1066.24 Β±22.28 / 1090.89 ms β +1.08x faster β
β QQuery 6 β 133.59 / 136.32 Β±2.93 / 141.42 ms β 134.30 / 140.19 Β±6.63 / 152.36 ms β no change β
β QQuery 7 β 1563.72 / 1581.82 Β±16.09 / 1609.94 ms β 1361.03 / 1383.17 Β±20.21 / 1417.51 ms β +1.14x faster β
β QQuery 8 β 1471.30 / 1899.23 Β±344.46 / 2196.56 ms β 1160.48 / 1254.40 Β±138.94 / 1530.54 ms β +1.51x faster β
β QQuery 9 β 2125.14 / 2373.70 Β±187.56 / 2699.90 ms β 1781.61 / 1916.18 Β±81.59 / 2024.46 ms β +1.24x faster β
β QQuery 10 β 544.27 / 550.30 Β±3.86 / 555.77 ms β 495.92 / 510.99 Β±10.93 / 524.00 ms β +1.08x faster β
β QQuery 11 β 455.29 / 469.03 Β±11.12 / 484.05 ms β 426.61 / 433.24 Β±5.62 / 442.76 ms β +1.08x faster β
β QQuery 12 β 295.00 / 301.36 Β±4.84 / 308.51 ms β 279.36 / 282.79 Β±2.83 / 286.06 ms β +1.07x faster β
β QQuery 13 β 370.67 / 377.16 Β±7.15 / 391.07 ms β 344.14 / 353.84 Β±5.61 / 360.05 ms β +1.07x faster β
β QQuery 14 β 193.64 / 199.80 Β±5.22 / 207.45 ms β 191.75 / 199.09 Β±6.65 / 209.34 ms β no change β
β QQuery 15 β 322.12 / 329.85 Β±6.15 / 339.31 ms β 321.21 / 329.66 Β±7.24 / 342.24 ms β no change β
β QQuery 16 β 125.14 / 126.31 Β±1.35 / 128.95 ms β 113.56 / 122.03 Β±8.02 / 136.95 ms β no change β
β QQuery 17 β 1638.60 / 1875.12 Β±120.43 / 1970.84 ms β 1356.61 / 1406.75 Β±36.24 / 1447.73 ms β +1.33x faster β
β QQuery 18 β 1598.31 / 1648.45 Β±45.52 / 1722.97 ms β 1361.97 / 1443.48 Β±55.54 / 1519.16 ms β +1.14x faster β
β QQuery 19 β 274.77 / 289.38 Β±25.56 / 340.35 ms β 274.65 / 286.05 Β±16.21 / 317.11 ms β no change β
β QQuery 20 β 442.18 / 459.13 Β±9.92 / 471.96 ms β 429.72 / 448.05 Β±11.89 / 466.01 ms β no change β
β QQuery 21 β 3252.47 / 3363.47 Β±59.18 / 3423.30 ms β 2599.98 / 2658.02 Β±30.81 / 2684.12 ms β +1.27x faster β
β QQuery 22 β 186.83 / 197.41 Β±7.15 / 208.14 ms β 154.25 / 161.09 Β±6.87 / 173.89 ms β +1.23x faster β
βββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββ
βββββββββββββββββββββββββββββββββ³βββββββββββββ
β Benchmark Summary β β
β‘βββββββββββββββββββββββββββββββββββββββββββββ©
β Total Time (HEAD) β 19341.99ms β
β Total Time (externalsorter) β 16089.26ms β
β Average Time (HEAD) β 879.18ms β
β Average Time (externalsorter) β 731.33ms β
β Queries Faster β 15 β
β Queries Slower β 0 β
β Queries with No Change β 7 β
β Queries with Failure β 0 β
βββββββββββββββββββββββββββββββββ΄βββββββββββββ
```
</p>
</details>
<details><summary>Resource Usage</summary>
**tpch10 β base (merge-base)**
| Metric | Value |
|--------|-------|
| Wall time | 97.1s |
| Peak memory | 11.2 GiB |
| Avg memory | 8.6 GiB |
| CPU user | 884.8s |
| CPU sys | 75.7s |
| Peak spill | 0 B |
**tpch10 β branch**
| Metric | Value |
|--------|-------|
| Wall time | 80.8s |
| Peak memory | 11.2 GiB |
| Avg memory | 7.8 GiB |
| CPU user | 795.9s |
| CPU sys | 68.9s |
| Peak spill | 0 B |
</details>
---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246955834
run benchmark tpcds
```
env:
PREFER_HASH_JOIN: false
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4247068843
π€ Benchmark completed (GKE) | [trigger](https://github.com/apache/datafusion/pull/21629#issuecomment-4246955834)
**Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB)
<details><summary>CPU Details (lscpu)</summary>
```
Architecture: aarch64
CPU op-mode(s): 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: ARM
Model name: Neoverse-V2
Model: 1
Thread(s) per core: 1
Core(s) per cluster: 16
Socket(s): -
Cluster(s): 1
Stepping: r0p1
BogoMIPS: 2000.00
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache: 1 MiB (16 instances)
L1i cache: 1 MiB (16 instances)
L2 cache: 32 MiB (16 instances)
L3 cache: 80 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Mitigation; CSV2, BHB
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Not affected
```
</details>
<details><summary>Details</summary>
<p>
```
Comparing HEAD and externalsorter
--------------------
Benchmark tpcds_sf1.json
--------------------
βββββββββββββ³βββββββββββββββββββββββββββββββββββββββββ³βββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββββ
β Query β HEAD β externalsorter β Change β
β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β QQuery 1 β 49.74 / 50.95 Β±0.80 / 52.26 ms β 49.77 / 50.30 Β±0.55 / 51.36 ms β no change β
β QQuery 2 β 143.00 / 143.81 Β±0.83 / 145.35 ms β 138.66 / 139.17 Β±0.36 / 139.58 ms β no change β
β QQuery 3 β 162.98 / 163.26 Β±0.21 / 163.53 ms β 157.53 / 157.95 Β±0.50 / 158.63 ms β no change β
β QQuery 4 β 1612.56 / 1660.28 Β±27.23 / 1688.23 ms β 1600.19 / 1626.35 Β±15.20 / 1645.67 ms β no change β
β QQuery 5 β 269.80 / 279.75 Β±5.67 / 286.05 ms β 260.95 / 267.50 Β±4.74 / 275.13 ms β no change β
β QQuery 6 β 225.06 / 231.01 Β±5.44 / 239.71 ms β 213.47 / 216.62 Β±3.33 / 220.82 ms β +1.07x faster β
β QQuery 7 β 369.21 / 373.52 Β±3.40 / 378.70 ms β 362.94 / 364.15 Β±1.10 / 365.71 ms β no change β
β QQuery 8 β 176.29 / 180.13 Β±2.51 / 183.75 ms β 171.53 / 174.34 Β±2.10 / 178.06 ms β no change β
β QQuery 9 β 102.02 / 111.04 Β±9.41 / 129.21 ms β 100.99 / 103.19 Β±2.14 / 106.76 ms β +1.08x faster β
β QQuery 10 β 245.07 / 248.04 Β±2.67 / 252.93 ms β 233.82 / 238.41 Β±2.95 / 242.19 ms β no change β
β QQuery 11 β 808.76 / 824.14 Β±10.53 / 836.10 ms β 810.15 / 819.46 Β±6.49 / 826.78 ms β no change β
β QQuery 12 β 50.88 / 52.58 Β±1.41 / 55.01 ms β 50.86 / 51.56 Β±0.71 / 52.81 ms β no change β
β QQuery 13 β 399.54 / 401.90 Β±2.09 / 405.30 ms β 400.11 / 403.87 Β±3.19 / 408.63 ms β no change β
β QQuery 14 β 2028.96 / 2043.27 Β±11.43 / 2062.97 ms β 1902.55 / 1914.86 Β±10.85 / 1932.72 ms β +1.07x faster β
β QQuery 15 β 88.42 / 89.51 Β±1.03 / 91.14 ms β 87.27 / 87.73 Β±0.45 / 88.54 ms β no change β
β QQuery 16 β 153.89 / 155.19 Β±1.80 / 158.68 ms β 150.93 / 152.57 Β±1.26 / 154.77 ms β no change β
β QQuery 17 β 358.74 / 363.74 Β±2.99 / 367.77 ms β 349.17 / 353.82 Β±2.78 / 357.20 ms β no change β
β QQuery 18 β 281.14 / 281.63 Β±0.43 / 282.22 ms β 274.75 / 281.17 Β±4.15 / 287.27 ms β no change β
β QQuery 19 β 227.90 / 231.61 Β±2.77 / 236.30 ms β 221.61 / 224.17 Β±2.06 / 226.49 ms β no change β
β QQuery 20 β 88.12 / 89.47 Β±1.22 / 91.77 ms β 88.41 / 89.97 Β±0.86 / 91.03 ms β no change β
β QQuery 21 β 798.90 / 808.36 Β±6.26 / 814.24 ms β 668.78 / 673.38 Β±3.70 / 677.90 ms β +1.20x faster β
β QQuery 22 β 388.75 / 399.20 Β±8.20 / 411.51 ms β 354.85 / 356.72 Β±2.03 / 360.51 ms β +1.12x faster β
β QQuery 23 β 1088.60 / 1104.21 Β±12.83 / 1120.18 ms β 1007.69 / 1030.83 Β±12.53 / 1043.52 ms β +1.07x faster β
β QQuery 24 β 870.55 / 877.91 Β±7.47 / 892.31 ms β 856.79 / 867.18 Β±6.16 / 872.77 ms β no change β
β QQuery 25 β 417.13 / 423.92 Β±5.61 / 432.55 ms β 410.87 / 414.43 Β±2.58 / 417.75 ms β no change β
β QQuery 26 β 197.96 / 200.97 Β±2.42 / 204.64 ms β 196.74 / 198.52 Β±1.63 / 201.33 ms β no change β
β QQuery 27 β 367.12 / 371.91 Β±4.35 / 378.67 ms β 357.63 / 360.99 Β±2.95 / 366.19 ms β no change β
β QQuery 28 β 150.19 / 151.29 Β±1.04 / 153.03 ms β 150.96 / 161.33 Β±12.39 / 185.19 ms β 1.07x slower β
β QQuery 29 β 362.15 / 366.13 Β±3.62 / 372.59 ms β 353.01 / 356.10 Β±2.05 / 358.46 ms β no change β
β QQuery 30 β 53.48 / 55.39 Β±1.12 / 56.79 ms β 54.71 / 56.57 Β±2.65 / 61.71 ms β no change β
β QQuery 31 β 625.69 / 628.59 Β±1.99 / 630.54 ms β 608.30 / 611.04 Β±1.82 / 612.67 ms β no change β
β QQuery 32 β 146.06 / 147.59 Β±1.33 / 149.77 ms β 143.35 / 144.30 Β±0.92 / 146.00 ms β no change β
β QQuery 33 β 213.59 / 216.13 Β±1.97 / 218.46 ms β 205.35 / 208.49 Β±2.17 / 211.51 ms β no change β
β QQuery 34 β 179.36 / 181.67 Β±1.21 / 182.70 ms β 174.26 / 176.07 Β±0.97 / 176.99 ms β no change β
β QQuery 35 β 232.86 / 238.51 Β±3.99 / 243.76 ms β 225.71 / 226.83 Β±0.76 / 227.90 ms β no change β
β QQuery 36 β 272.93 / 274.49 Β±1.27 / 276.02 ms β 264.54 / 267.47 Β±3.06 / 271.93 ms β no change β
β QQuery 37 β 274.11 / 277.05 Β±2.73 / 282.14 ms β 260.50 / 264.81 Β±2.52 / 267.87 ms β no change β
β QQuery 38 β 191.40 / 194.86 Β±2.31 / 198.45 ms β 184.14 / 187.10 Β±2.34 / 190.80 ms β no change β
β QQuery 39 β 3617.17 / 3646.86 Β±18.70 / 3667.45 ms β 3294.92 / 3317.14 Β±29.90 / 3376.26 ms β +1.10x faster β
β QQuery 40 β 164.24 / 166.25 Β±2.16 / 170.17 ms β 159.06 / 162.57 Β±3.56 / 168.98 ms β no change β
β QQuery 41 β 15.41 / 16.22 Β±1.43 / 19.07 ms β 14.34 / 14.98 Β±0.61 / 16.01 ms β +1.08x faster β
β QQuery 42 β 164.30 / 164.65 Β±0.40 / 165.42 ms β 158.15 / 159.89 Β±1.31 / 161.79 ms β no change β
β QQuery 43 β 146.78 / 148.48 Β±1.35 / 149.84 ms β 137.90 / 138.84 Β±1.51 / 141.84 ms β +1.07x faster β
β QQuery 44 β 13.23 / 15.13 Β±1.24 / 16.26 ms β 12.62 / 13.15 Β±0.57 / 14.15 ms β +1.15x faster β
β QQuery 45 β 65.02 / 66.32 Β±1.37 / 68.85 ms β 66.32 / 67.17 Β±0.76 / 68.54 ms β no change β
β QQuery 46 β 343.05 / 345.47 Β±2.48 / 350.17 ms β 328.91 / 330.68 Β±1.17 / 332.10 ms β no change β
β QQuery 47 β 746.08 / 758.57 Β±6.77 / 766.02 ms β 712.07 / 717.79 Β±4.98 / 726.32 ms β +1.06x faster β
β QQuery 48 β 290.50 / 293.13 Β±2.59 / 297.76 ms β 285.39 / 290.38 Β±4.62 / 299.00 ms β no change β
β QQuery 49 β 258.58 / 261.84 Β±2.10 / 264.11 ms β 257.12 / 259.94 Β±3.48 / 266.80 ms β no change β
β QQuery 50 β 218.33 / 221.90 Β±3.03 / 225.86 ms β 217.04 / 218.17 Β±1.09 / 219.97 ms β no change β
β QQuery 51 β 228.10 / 229.72 Β±1.64 / 232.87 ms β 217.90 / 219.42 Β±1.25 / 220.85 ms β no change β
β QQuery 52 β 160.80 / 164.32 Β±2.46 / 168.29 ms β 157.52 / 159.53 Β±1.82 / 162.55 ms β no change β
β QQuery 53 β 166.15 / 168.23 Β±1.17 / 169.62 ms β 155.34 / 156.44 Β±0.75 / 157.32 ms β +1.08x faster β
β QQuery 54 β 250.91 / 257.78 Β±4.15 / 263.02 ms β 241.27 / 244.68 Β±2.99 / 249.44 ms β +1.05x faster β
β QQuery 55 β 161.96 / 164.74 Β±2.30 / 167.83 ms β 156.23 / 158.15 Β±1.68 / 160.52 ms β no change β
β QQuery 56 β 214.98 / 219.33 Β±4.55 / 226.64 ms β 207.29 / 208.81 Β±1.32 / 210.52 ms β no change β
β QQuery 57 β 356.96 / 358.95 Β±1.69 / 360.93 ms β 348.91 / 352.74 Β±3.72 / 359.38 ms β no change β
β QQuery 58 β 391.11 / 395.51 Β±3.24 / 399.53 ms β 373.90 / 377.29 Β±2.57 / 380.86 ms β no change β
β QQuery 59 β 289.96 / 292.41 Β±2.07 / 295.73 ms β 280.62 / 284.21 Β±2.44 / 287.93 ms β no change β
β QQuery 60 β 212.27 / 216.62 Β±3.16 / 220.27 ms β 205.52 / 207.67 Β±1.41 / 209.58 ms β no change β
β QQuery 61 β 282.98 / 288.94 Β±4.52 / 295.97 ms β 271.81 / 278.95 Β±4.02 / 283.10 ms β no change β
β QQuery 62 β 81.34 / 83.01 Β±1.19 / 84.95 ms β 75.65 / 76.16 Β±0.44 / 76.89 ms β +1.09x faster β
β QQuery 63 β 167.62 / 170.02 Β±1.30 / 171.05 ms β 156.78 / 158.38 Β±1.02 / 159.67 ms β +1.07x faster β
β QQuery 64 β 1447.80 / 1453.70 Β±4.84 / 1459.36 ms β 1416.77 / 1426.33 Β±8.52 / 1439.37 ms β no change β
β QQuery 65 β 332.63 / 335.47 Β±1.84 / 338.39 ms β 319.70 / 323.60 Β±3.64 / 329.99 ms β no change β
β QQuery 66 β 294.74 / 303.12 Β±5.28 / 309.75 ms β 241.97 / 245.41 Β±2.61 / 248.39 ms β +1.24x faster β
β QQuery 67 β 267.82 / 270.77 Β±1.64 / 272.84 ms β 274.05 / 277.32 Β±3.64 / 284.19 ms β no change β
β QQuery 68 β 395.80 / 403.19 Β±6.40 / 414.43 ms β 388.01 / 395.78 Β±6.20 / 404.99 ms β no change β
β QQuery 69 β 241.39 / 243.05 Β±1.26 / 245.20 ms β 229.77 / 232.45 Β±1.80 / 234.21 ms β no change β
β QQuery 70 β 438.48 / 440.98 Β±2.52 / 444.54 ms β 414.03 / 418.52 Β±3.54 / 422.93 ms β +1.05x faster β
β QQuery 71 β 204.47 / 207.46 Β±2.60 / 211.64 ms β 197.01 / 201.22 Β±3.24 / 205.26 ms β no change β
β QQuery 72 β 8234.94 / 8806.84 Β±288.40 / 9000.55 ms β 7393.54 / 7678.73 Β±151.01 / 7816.87 ms β +1.15x faster β
β QQuery 73 β 177.60 / 181.67 Β±2.63 / 184.59 ms β 171.45 / 175.37 Β±4.00 / 183.02 ms β no change β
β QQuery 74 β 568.83 / 577.38 Β±5.58 / 583.13 ms β 541.29 / 549.82 Β±4.41 / 553.64 ms β no change β
β QQuery 75 β 504.31 / 516.57 Β±6.96 / 525.41 ms β 488.70 / 494.04 Β±5.93 / 505.26 ms β no change β
β QQuery 76 β 134.29 / 138.36 Β±2.20 / 140.68 ms β 135.17 / 137.80 Β±1.74 / 140.62 ms β no change β
β QQuery 77 β 273.85 / 279.12 Β±2.82 / 281.87 ms β 261.98 / 268.83 Β±5.72 / 275.75 ms β no change β
β QQuery 78 β 559.82 / 565.84 Β±4.92 / 572.65 ms β 543.23 / 546.52 Β±2.70 / 549.62 ms β no change β
β QQuery 79 β 332.91 / 338.18 Β±3.76 / 344.34 ms β 323.71 / 328.48 Β±2.85 / 332.24 ms β no change β
β QQuery 80 β 451.16 / 461.80 Β±8.86 / 471.83 ms β 440.33 / 451.68 Β±6.86 / 458.92 ms β no change β
β QQuery 81 β 58.09 / 62.79 Β±4.42 / 70.88 ms β 56.14 / 60.33 Β±4.38 / 67.49 ms β no change β
β QQuery 82 β 315.86 / 318.35 Β±3.05 / 324.20 ms β 293.30 / 295.47 Β±1.69 / 297.35 ms β +1.08x faster β
β QQuery 83 β 66.32 / 67.42 Β±1.29 / 69.78 ms β 63.49 / 65.19 Β±1.51 / 67.97 ms β no change β
β QQuery 84 β 65.81 / 66.72 Β±0.66 / 67.50 ms β 62.26 / 63.12 Β±0.90 / 64.81 ms β +1.06x faster β
β QQuery 85 β 176.59 / 179.81 Β±2.14 / 182.52 ms β 166.38 / 168.19 Β±2.26 / 172.64 ms β +1.07x faster β
β QQuery 86 β 45.63 / 46.60 Β±0.89 / 48.20 ms β 44.58 / 45.77 Β±0.92 / 46.88 ms β no change β
β QQuery 87 β 192.74 / 194.62 Β±1.92 / 198.25 ms β 185.30 / 187.57 Β±2.30 / 191.42 ms β no change β
β QQuery 88 β 297.82 / 310.03 Β±6.59 / 317.38 ms β 275.13 / 285.26 Β±5.81 / 291.71 ms β +1.09x faster β
β QQuery 89 β 170.62 / 174.64 Β±4.64 / 183.71 ms β 159.64 / 163.07 Β±4.05 / 170.83 ms β +1.07x faster β
β QQuery 90 β 40.99 / 41.66 Β±0.50 / 42.40 ms β 37.74 / 38.55 Β±0.57 / 39.24 ms β +1.08x faster β
β QQuery 91 β 70.57 / 71.76 Β±0.91 / 73.38 ms β 68.61 / 69.82 Β±1.00 / 71.02 ms β no change β
β QQuery 92 β 82.07 / 83.19 Β±0.76 / 84.21 ms β 80.72 / 81.13 Β±0.39 / 81.84 ms β no change β
β QQuery 93 β 380.35 / 389.69 Β±6.39 / 397.77 ms β 403.81 / 411.73 Β±5.60 / 420.16 ms β 1.06x slower β
β QQuery 94 β 92.28 / 93.41 Β±0.71 / 94.34 ms β 89.67 / 92.82 Β±4.10 / 100.87 ms β no change β
β QQuery 95 β 166.06 / 167.38 Β±1.03 / 168.77 ms β 162.40 / 164.19 Β±1.14 / 165.74 ms β no change β
β QQuery 96 β 126.90 / 128.13 Β±0.87 / 129.44 ms β 120.92 / 122.47 Β±1.78 / 125.84 ms β no change β
β QQuery 97 β 198.32 / 200.22 Β±1.17 / 201.88 ms β 192.65 / 194.61 Β±1.81 / 197.68 ms β no change β
β QQuery 98 β 183.37 / 185.92 Β±1.98 / 187.89 ms β 181.32 / 183.52 Β±1.17 / 184.45 ms β no change β
β QQuery 99 β 205.39 / 207.60 Β±2.10 / 211.09 ms β 191.93 / 195.48 Β±2.21 / 197.73 ms β +1.06x faster β
βββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββ
βββββββββββββββββββββββββββββββββ³βββββββββββββ
β Benchmark Summary β β
β‘βββββββββββββββββββββββββββββββββββββββββββββ©
β Total Time (HEAD) β 42520.79ms β
β Total Time (externalsorter) β 39892.64ms β
β Average Time (HEAD) β 429.50ms β
β Average Time (externalsorter) β 402.96ms β
β Queries Faster β 25 β
β Queries Slower β 2 β
β Queries with No Change β 72 β
β Queries with Failure β 0 β
βββββββββββββββββββββββββββββββββ΄βββββββββββββ
```
</p>
</details>
<details><summary>Resource Usage</summary>
**tpcds β base (merge-base)**
| Metric | Value |
|--------|-------|
| Wall time | 213.1s |
| Peak memory | 28.6 GiB |
| Avg memory | 6.9 GiB |
| CPU user | 874.8s |
| CPU sys | 90.3s |
| Peak spill | 0 B |
**tpcds β branch**
| Metric | Value |
|--------|-------|
| Wall time | 199.8s |
| Peak memory | 18.4 GiB |
| Avg memory | 6.0 GiB |
| CPU user | 842.4s |
| CPU sys | 71.8s |
| Peak spill | 0 B |
</details>
---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246734700
run benchmark tpch10
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#discussion_r3090863657
##########
datafusion/physical-plan/src/sorts/sort.rs:
##########
@@ -95,116 +93,76 @@ impl ExternalSorterMetrics {
///
/// # Algorithm
///
-/// 1. get a non-empty new batch from input
+/// Incoming batches are coalesced via [`BatchCoalescer`] to
+/// `sort_coalesce_target_rows` (default 32768) before sorting. This
+/// reduces merge fan-in by producing fewer, larger sorted runs.
///
-/// 2. check with the memory manager there is sufficient space to
-/// buffer the batch in memory.
+/// Each coalesced batch is sorted immediately and stored as a
+/// pre-sorted run.
///
-/// 2.1 if memory is sufficient, buffer batch in memory, go to 1.
+/// 1. For each incoming batch:
+/// - Reserve memory (2x batch size). If reservation fails, flush
+/// the coalescer, spill all sorted runs to disk, then retry.
+/// - Push batch into the coalescer.
+/// - If the coalescer reached its target: sort the coalesced batch
+/// and store as a new sorted run.
///
-/// 2.2 if no more memory is available, sort all buffered batches and
-/// spill to file. buffer the next batch in memory, go to 1.
-///
-/// 3. when input is exhausted, merge all in memory batches and spills
-/// to get a total order.
+/// 2. When input is exhausted, merge all sorted runs (and any spill
+/// files) to produce a total order.
///
/// # When data fits in available memory
///
-/// If there is sufficient memory, data is sorted in memory to produce the output
+/// Sorted runs are merged in memory using a loser-tree k-way merge
+/// (via [`StreamingMergeBuilder`]).
///
/// ```text
-/// βββββββ
-/// β 2 β
-/// β 3 β
-/// β 1 ββ β β β β β β β β β
-/// β 4 β
-/// β 2 β β
-/// βββββββ βΌ
-/// βββββββ
-/// β 1 β In memory
-/// β 4 ββ β β β β ββΆ sort/merge β β β β ββΆ total sorted output
-/// β 1 β
-/// βββββββ β²
-/// ... β
-///
-/// βββββββ β
-/// β 4 β
-/// β 3 ββ β β β β β β β β β
-/// βββββββ
-///
-/// in_mem_batches
+/// ββββββββββββ ββββββββββββββ ββββββββ ββββββββββββββ
+/// β Incoming ββββββΆβ Batch ββββββΆβ Sort ββββββΆβ Sorted Run β
+/// β Batches β β Coalescer β β β β (in memory)β
+/// ββββββββββββ ββββββββββββββ ββββββββ βββββββ¬βββββββ
+/// β
+/// ββββββββββββββββ
+/// βΌ
+/// k-way merge (loser tree)
+/// β
+/// βΌ
+/// total sorted output
/// ```
///
/// # When data does not fit in available memory
///
-/// When memory is exhausted, data is first sorted and written to one
-/// or more spill files on disk:
-///
-/// ```text
-/// βββββββ .βββββββββββββββββ.
-/// β 2 β ( )
-/// β 3 β β`βββββββββββββββββ'β
-/// β 1 ββ β β β β β β β ββββββ β
-/// β 4 β β β β 1 ββ β
-/// β 2 β β β... ββ β
-/// βββββββ βΌ β β 4 ββ β β β β
-/// βββββββ β βββββββ 1 ββ β
-/// β 1 β In memory β ββββββ β ββ β
-/// β 4 ββ β βΆ sort/merge β β β β βΌ β β β β ββΆ ... ββ β
-/// β 1 β and write to file β β ββ β
-/// βββββββ β 4 ββ β
-/// ... β² β βββββββ β
-/// β β ββββββ β
-/// βββββββ β.βββββββββββββββββ.β
-/// β 4 β β ( )
-/// β 3 ββ β β β β β β `βββββββββββββββββ'
-/// βββββββ
-///
-/// in_mem_batches spills
-/// (file on disk in Arrow
-/// IPC format)
-/// ```
-///
-/// Once the input is completely read, the spill files are read and
-/// merged with any in memory batches to produce a single total sorted
-/// output:
+/// When memory is exhausted, sorted runs are spilled directly to disk
+/// (one spill file per run β no merge needed since runs are already
+/// sorted). `MultiLevelMergeBuilder` handles the final merge from disk
+/// with dynamic fan-in.
///
/// ```text
-/// .βββββββββββββββββ.
-/// ( )
-/// β`βββββββββββββββββ'β
-/// β ββββββ β
-/// β β 1 ββ β
-/// β β... ββ β β β β βββ β β β β β
-/// β β 4 ββ ββββββ β β
-/// β βββββββ β 1 ββ β βΌ
-/// β ββββββ β ββ β
-/// β β... ββ βββ β β βΆ merge β β ββΆ total sorted output
-/// β β ββ β
-/// β β 4 ββ β β²
-/// β βββββββ β β
-/// β ββββββ β
-/// β.βββββββββββββββββ.β β
-/// ( )
-/// `βββββββββββββββββ' β
-/// spills
+/// ββββββββββββ ββββββββββββββ ββββββββ ββββββββββββββ
+/// β Incoming ββββββΆβ Batch ββββββΆβ Sort ββββββΆβ Sorted Run β
Review Comment:
Yeah I think something like that could work.
The propagation doesn't seem too complex I think, just change the target batch size of te inner op based on the desired one.
I agree it is out of scope.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4253348811
run benchmark sort
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246733187
Lets compare to hash join
run benchmark tpch10
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246885904
π€ Criterion benchmark running (GKE) | [trigger](https://github.com/apache/datafusion/pull/21629#issuecomment-4246870829)
**Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB) | `Linux bench-c4246870829-1257-bwm8p 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux`
<details><summary>CPU Details (lscpu)</summary>
```
Architecture: aarch64
CPU op-mode(s): 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: ARM
Model name: Neoverse-V2
Model: 1
Thread(s) per core: 1
Core(s) per cluster: 16
Socket(s): -
Cluster(s): 1
Stepping: r0p1
BogoMIPS: 2000.00
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache: 1 MiB (16 instances)
L1i cache: 1 MiB (16 instances)
L2 cache: 32 MiB (16 instances)
L3 cache: 80 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Mitigation; CSV2, BHB
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Not affected
```
</details>
Comparing externalsorter (32a688271e2c9cb67b47454a2bc72f3cb926cfee) to e6b32fe (merge-base) [diff](https://github.com/apache/datafusion/compare/e6b32fe66b4e8e313ff79a9c45585d1a4bc2a19e..32a688271e2c9cb67b47454a2bc72f3cb926cfee)
BENCH_NAME=tpch_sort
BENCH_COMMAND=cargo bench --features=parquet --bench tpch_sort
BENCH_FILTER=
Results will be posted here when complete
---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4255649635
run benchmark sort
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4254421073
I fear my sort benchmark scale up might have killed the benchmark bot :(
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4259841218
> Would be nice to see results in `sort` bench / `sort_tpch` etc. to see if we didnt have any regressions.
Iβll try to run locally with the scaled up `sort` benchmark. We may want to consider scaling some of the scenarios independently if 1M is too big to apply across the board for the bot.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich commented on code in PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#discussion_r3081924897
##########
datafusion/common/src/config.rs:
##########
@@ -555,7 +555,17 @@ config_namespace! {
/// When sorting, below what size should data be concatenated
/// and sorted in a single RecordBatch rather than sorted in
/// batches and merged.
- pub sort_in_place_threshold_bytes: usize, default = 1024 * 1024
+ ///
+ /// Deprecated: this option is no longer used. The sort pipeline
+ /// now always coalesces batches before sorting. Use
+ /// `sort_coalesce_target_rows` instead.
+ pub sort_in_place_threshold_bytes: usize, warn = "`sort_in_place_threshold_bytes` is deprecated and ignored. Use `sort_coalesce_target_rows` instead.", default = 1024 * 1024
+
+ /// Target number of rows to coalesce before sorting in ExternalSorter.
+ ///
+ /// Larger values reduce merge fan-in by producing fewer, larger
+ /// sorted runs.
+ pub sort_coalesce_target_rows: usize, default = 32768
Review Comment:
Yeah I suspect we'd want to do a good sensitivity analysis on different types and batch sizes for `lexsort_to_indices` (and eventually the radix sort kernel). We might hit a point of diminishing returns/cache friendliness if our coalesced batches get too large.
This design also first spills from the sorted runs, so holding more unsorted rows in the coalescer may make it more likely for us to trigger spilling.
I'm definitely of the mind that we can and should tune this, but unclear what even a reasonable default right now would be. In Comet where we run TPC-H SF 1000, for example, I suspect we'll want longer sorted runs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246886420
Benchmark for [this request](https://github.com/apache/datafusion/pull/21629#issuecomment-4246870829) failed.
Last 20 lines of output:
<details><summary>Click to expand</summary>
```
struct_query_sql
substr
substr_index
substring
sum
to_char
to_hex
to_local_time
to_time
to_timestamp
topk_aggregate
topk_repartition
translate
trim
trunc
unhex
upper
uuid
window_query_sql
with_hashes
```
</details>
---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "gratus00 (via GitHub)" <gi...@apache.org>.
gratus00 commented on code in PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#discussion_r3097558112
##########
datafusion/physical-plan/src/sorts/sort.rs:
##########
@@ -402,381 +496,199 @@ impl ExternalSorter {
self.metrics.spill_metrics.spill_file_count.value()
}
- /// Appending globally sorted batches to the in-progress spill file, and clears
- /// the `globally_sorted_batches` (also its memory reservation) afterwards.
- async fn consume_and_spill_append(
- &mut self,
- globally_sorted_batches: &mut Vec<RecordBatch>,
- ) -> Result<()> {
- if globally_sorted_batches.is_empty() {
- return Ok(());
- }
-
- // Lazily initialize the in-progress spill file
- if self.in_progress_spill_file.is_none() {
- self.in_progress_spill_file =
- Some((self.spill_manager.create_in_progress_file("Sorting")?, 0));
- }
-
- Self::organize_stringview_arrays(globally_sorted_batches)?;
-
- debug!("Spilling sort data of ExternalSorter to disk whilst inserting");
-
- let batches_to_spill = std::mem::take(globally_sorted_batches);
- self.reservation.free();
-
- let (in_progress_file, max_record_batch_size) =
- self.in_progress_spill_file.as_mut().ok_or_else(|| {
- internal_datafusion_err!("In-progress spill file should be initialized")
- })?;
-
- for batch in batches_to_spill {
- in_progress_file.append_batch(&batch)?;
-
- *max_record_batch_size =
- (*max_record_batch_size).max(batch.get_sliced_size()?);
- }
-
- assert_or_internal_err!(
- globally_sorted_batches.is_empty(),
- "This function consumes globally_sorted_batches, so it should be empty after taking."
- );
-
- Ok(())
- }
-
- /// Finishes the in-progress spill file and moves it to the finished spill files.
- async fn spill_finish(&mut self) -> Result<()> {
- let (mut in_progress_file, max_record_batch_memory) =
- self.in_progress_spill_file.take().ok_or_else(|| {
- internal_datafusion_err!("Should be called after `spill_append`")
- })?;
- let spill_file = in_progress_file.finish()?;
-
- if let Some(spill_file) = spill_file {
- self.finished_spill_files.push(SortedSpillFile {
- file: spill_file,
- max_record_batch_memory,
- });
- }
-
- Ok(())
- }
-
- /// Reconstruct `globally_sorted_batches` to organize the payload buffers of each
- /// `StringViewArray` in sequential order by calling `gc()` on them.
- ///
- /// Note this is a workaround until <https://github.com/apache/arrow-rs/issues/7185> is
- /// available
- ///
- /// # Rationale
- /// After (merge-based) sorting, all batches will be sorted into a single run,
- /// but physically this sorted run is chunked into many small batches. For
- /// `StringViewArray`s inside each sorted run, their inner buffers are not
- /// re-constructed by default, leading to non-sequential payload locations
- /// (permutated by `interleave()` Arrow kernel). A single payload buffer might
- /// be shared by multiple `RecordBatch`es.
- /// When writing each batch to disk, the writer has to write all referenced buffers,
- /// because they have to be read back one by one to reduce memory usage. This
- /// causes extra disk reads and writes, and potentially execution failure.
+ /// Spills sorted runs to disk.
///
- /// # Example
- /// Before sorting:
- /// batch1 -> buffer1
- /// batch2 -> buffer2
+ /// Two strategies depending on available merge headroom:
///
- /// sorted_batch1 -> buffer1
- /// -> buffer2
- /// sorted_batch2 -> buffer1
- /// -> buffer2
+ /// - **With headroom** (`merge_reservation > 0`): merge all runs into
+ /// a single globally-sorted stream, then write to one spill file.
+ /// Fewer spill files = lower fan-in for the final MultiLevelMerge.
///
- /// Then when spilling each batch, the writer has to write all referenced buffers
- /// repeatedly.
- fn organize_stringview_arrays(
- globally_sorted_batches: &mut Vec<RecordBatch>,
- ) -> Result<()> {
- let mut organized_batches = Vec::with_capacity(globally_sorted_batches.len());
-
- for batch in globally_sorted_batches.drain(..) {
- let mut new_columns: Vec<Arc<dyn Array>> =
- Vec::with_capacity(batch.num_columns());
+ /// - **Without headroom** (`merge_reservation == 0`): spill each run
+ /// as its own file. Avoids allocating merge cursor infrastructure
+ /// when the pool has no room. MultiLevelMerge handles the higher
+ /// fan-in with dynamic memory management.
+ async fn spill_sorted_runs(&mut self) -> Result<()> {
+ assert_or_internal_err!(
+ self.has_sorted_runs(),
+ "sorted_runs must not be empty when attempting to spill"
+ );
- let mut arr_mutated = false;
- for array in batch.columns() {
- if let Some(string_view_array) =
- array.as_any().downcast_ref::<StringViewArray>()
- {
- let new_array = string_view_array.gc();
- new_columns.push(Arc::new(new_array));
- arr_mutated = true;
- } else {
- new_columns.push(Arc::clone(array));
- }
- }
+ if self.merge_reservation.size() > 0 && self.sorted_runs.len() > 1 {
Review Comment:
Hi, i'm tracing the spill cycles, and the first spill's merge_reservation value starts at 0 while others grow at the end of `spill_sorted_runs`
the second spill could be something small like 1024 and still take the merge path
is `>0` just a good enough heuristic we are using without trying to guarantee actual headroom for the merge process?
feel free to correct me, i'm new and i'm trying to learn!!
##########
datafusion/physical-plan/src/sorts/sort.rs:
##########
@@ -402,381 +496,199 @@ impl ExternalSorter {
self.metrics.spill_metrics.spill_file_count.value()
}
- /// Appending globally sorted batches to the in-progress spill file, and clears
- /// the `globally_sorted_batches` (also its memory reservation) afterwards.
- async fn consume_and_spill_append(
- &mut self,
- globally_sorted_batches: &mut Vec<RecordBatch>,
- ) -> Result<()> {
- if globally_sorted_batches.is_empty() {
- return Ok(());
- }
-
- // Lazily initialize the in-progress spill file
- if self.in_progress_spill_file.is_none() {
- self.in_progress_spill_file =
- Some((self.spill_manager.create_in_progress_file("Sorting")?, 0));
- }
-
- Self::organize_stringview_arrays(globally_sorted_batches)?;
-
- debug!("Spilling sort data of ExternalSorter to disk whilst inserting");
-
- let batches_to_spill = std::mem::take(globally_sorted_batches);
- self.reservation.free();
-
- let (in_progress_file, max_record_batch_size) =
- self.in_progress_spill_file.as_mut().ok_or_else(|| {
- internal_datafusion_err!("In-progress spill file should be initialized")
- })?;
-
- for batch in batches_to_spill {
- in_progress_file.append_batch(&batch)?;
-
- *max_record_batch_size =
- (*max_record_batch_size).max(batch.get_sliced_size()?);
- }
-
- assert_or_internal_err!(
- globally_sorted_batches.is_empty(),
- "This function consumes globally_sorted_batches, so it should be empty after taking."
- );
-
- Ok(())
- }
-
- /// Finishes the in-progress spill file and moves it to the finished spill files.
- async fn spill_finish(&mut self) -> Result<()> {
- let (mut in_progress_file, max_record_batch_memory) =
- self.in_progress_spill_file.take().ok_or_else(|| {
- internal_datafusion_err!("Should be called after `spill_append`")
- })?;
- let spill_file = in_progress_file.finish()?;
-
- if let Some(spill_file) = spill_file {
- self.finished_spill_files.push(SortedSpillFile {
- file: spill_file,
- max_record_batch_memory,
- });
- }
-
- Ok(())
- }
-
- /// Reconstruct `globally_sorted_batches` to organize the payload buffers of each
- /// `StringViewArray` in sequential order by calling `gc()` on them.
- ///
- /// Note this is a workaround until <https://github.com/apache/arrow-rs/issues/7185> is
- /// available
- ///
- /// # Rationale
- /// After (merge-based) sorting, all batches will be sorted into a single run,
- /// but physically this sorted run is chunked into many small batches. For
- /// `StringViewArray`s inside each sorted run, their inner buffers are not
- /// re-constructed by default, leading to non-sequential payload locations
- /// (permutated by `interleave()` Arrow kernel). A single payload buffer might
- /// be shared by multiple `RecordBatch`es.
- /// When writing each batch to disk, the writer has to write all referenced buffers,
- /// because they have to be read back one by one to reduce memory usage. This
- /// causes extra disk reads and writes, and potentially execution failure.
+ /// Spills sorted runs to disk.
///
- /// # Example
- /// Before sorting:
- /// batch1 -> buffer1
- /// batch2 -> buffer2
+ /// Two strategies depending on available merge headroom:
///
- /// sorted_batch1 -> buffer1
- /// -> buffer2
- /// sorted_batch2 -> buffer1
- /// -> buffer2
+ /// - **With headroom** (`merge_reservation > 0`): merge all runs into
+ /// a single globally-sorted stream, then write to one spill file.
+ /// Fewer spill files = lower fan-in for the final MultiLevelMerge.
///
- /// Then when spilling each batch, the writer has to write all referenced buffers
- /// repeatedly.
- fn organize_stringview_arrays(
- globally_sorted_batches: &mut Vec<RecordBatch>,
- ) -> Result<()> {
- let mut organized_batches = Vec::with_capacity(globally_sorted_batches.len());
-
- for batch in globally_sorted_batches.drain(..) {
- let mut new_columns: Vec<Arc<dyn Array>> =
- Vec::with_capacity(batch.num_columns());
+ /// - **Without headroom** (`merge_reservation == 0`): spill each run
+ /// as its own file. Avoids allocating merge cursor infrastructure
+ /// when the pool has no room. MultiLevelMerge handles the higher
+ /// fan-in with dynamic memory management.
+ async fn spill_sorted_runs(&mut self) -> Result<()> {
+ assert_or_internal_err!(
+ self.has_sorted_runs(),
+ "sorted_runs must not be empty when attempting to spill"
+ );
- let mut arr_mutated = false;
- for array in batch.columns() {
- if let Some(string_view_array) =
- array.as_any().downcast_ref::<StringViewArray>()
- {
- let new_array = string_view_array.gc();
- new_columns.push(Arc::new(new_array));
- arr_mutated = true;
- } else {
- new_columns.push(Arc::clone(array));
- }
- }
+ if self.merge_reservation.size() > 0 && self.sorted_runs.len() > 1 {
+ debug!(
+ "Spilling {} sorted runs via merge to single file",
+ self.sorted_runs.len()
+ );
+ // Free merge_reservation to provide pool headroom for the
+ // merge cursor allocation. Re-reserved at the end.
+ self.merge_reservation.free();
- let organized_batch = if arr_mutated {
- RecordBatch::try_new(batch.schema(), new_columns)?
- } else {
- batch
- };
+ let mut sorted_stream =
+ self.merge_sorted_runs(self.metrics.baseline.intermediate())?;
+ assert_or_internal_err!(
+ self.sorted_runs.is_empty(),
+ "sorted_runs should be empty after constructing sorted stream"
+ );
- organized_batches.push(organized_batch);
- }
+ let mut in_progress =
+ self.spill_manager.create_in_progress_file("Sorting")?;
+ let mut max_batch_memory = 0usize;
- *globally_sorted_batches = organized_batches;
+ while let Some(batch) = sorted_stream.next().await {
+ let batch = batch?;
+ max_batch_memory = max_batch_memory.max(batch.get_sliced_size()?);
+ in_progress.append_batch(&batch)?;
+ }
- Ok(())
- }
+ drop(sorted_stream);
+ self.reservation.free();
- /// Sorts the in-memory batches and merges them into a single sorted run, then writes
- /// the result to spill files.
- async fn sort_and_spill_in_mem_batches(&mut self) -> Result<()> {
- assert_or_internal_err!(
- !self.in_mem_batches.is_empty(),
- "in_mem_batches must not be empty when attempting to sort and spill"
- );
+ let spill_file = in_progress.finish()?;
+ if let Some(spill_file) = spill_file {
+ self.finished_spill_files.push(SortedSpillFile {
+ file: spill_file,
+ max_record_batch_memory: max_batch_memory,
+ });
+ }
+ } else {
+ // No merge headroom or single run: spill each run as its own
+ // file to avoid allocating merge cursor infrastructure.
+ debug!(
+ "Spilling {} sorted runs as individual files (no merge headroom)",
+ self.sorted_runs.len()
+ );
+ let all_runs = std::mem::take(&mut self.sorted_runs);
+ self.sorted_runs_memory = 0;
+ for run in all_runs {
+ let run_size: usize = run.iter().map(get_record_batch_memory_size).sum();
+
+ let mut in_progress =
+ self.spill_manager.create_in_progress_file("Sorting")?;
+ let mut max_batch_memory = 0usize;
+ for batch in &run {
+ in_progress.append_batch(batch)?;
+ max_batch_memory = max_batch_memory.max(batch.get_sliced_size()?);
+ }
- // Release the memory reserved for merge back to the pool so
- // there is some left when `in_mem_sort_stream` requests an
- // allocation. At the end of this function, memory will be
- // reserved again for the next spill.
- self.merge_reservation.free();
+ let spill_file = in_progress.finish()?;
+ if let Some(spill_file) = spill_file {
+ self.finished_spill_files.push(SortedSpillFile {
+ file: spill_file,
+ max_record_batch_memory: max_batch_memory,
+ });
+ }
- let mut sorted_stream =
- self.in_mem_sort_stream(self.metrics.baseline.intermediate())?;
- // After `in_mem_sort_stream()` is constructed, all `in_mem_batches` is taken
- // to construct a globally sorted stream.
- assert_or_internal_err!(
- self.in_mem_batches.is_empty(),
- "in_mem_batches should be empty after constructing sorted stream"
- );
- // 'global' here refers to all buffered batches when the memory limit is
- // reached. This variable will buffer the sorted batches after
- // sort-preserving merge and incrementally append to spill files.
- let mut globally_sorted_batches: Vec<RecordBatch> = vec![];
-
- while let Some(batch) = sorted_stream.next().await {
- let batch = batch?;
- let sorted_size = get_reserved_bytes_for_record_batch(&batch)?;
- if self.reservation.try_grow(sorted_size).is_err() {
- // Although the reservation is not enough, the batch is
- // already in memory, so it's okay to combine it with previously
- // sorted batches, and spill together.
- globally_sorted_batches.push(batch);
- self.consume_and_spill_append(&mut globally_sorted_batches)
- .await?; // reservation is freed in spill()
- } else {
- globally_sorted_batches.push(batch);
+ drop(run);
+ self.reservation
+ .shrink(run_size.min(self.reservation.size()));
}
}
- // Drop early to free up memory reserved by the sorted stream, otherwise the
- // upcoming `self.reserve_memory_for_merge()` may fail due to insufficient memory.
- drop(sorted_stream);
-
- self.consume_and_spill_append(&mut globally_sorted_batches)
- .await?;
- self.spill_finish().await?;
-
- // Sanity check after spilling
- let buffers_cleared_property =
- self.in_mem_batches.is_empty() && globally_sorted_batches.is_empty();
- assert_or_internal_err!(
- buffers_cleared_property,
- "in_mem_batches and globally_sorted_batches should be cleared before"
- );
-
- // Reserve headroom for next sort/merge
self.reserve_memory_for_merge()?;
Ok(())
}
- /// Consumes in_mem_batches returning a sorted stream of
- /// batches. This proceeds in one of two ways:
- ///
- /// # Small Datasets
- ///
- /// For "smaller" datasets, the data is first concatenated into a
- /// single batch and then sorted. This is often faster than
- /// sorting and then merging.
+ /// Merges the pre-sorted runs stored in `sorted_runs` into a single
+ /// sorted output stream. Each run is already sorted internally; this
+ /// method k-way merges them using the loser tree.
///
/// ```text
- /// βββββββ
- /// β 2 β
- /// β 3 β
- /// β 1 ββ β β β β βββββββ
- /// β 4 β β 2 β
- /// β 2 β β β 3 β
- /// βββββββ β 1 β sorted output
- /// βββββββ βΌ β 4 β stream
- /// β 1 β β 2 β
- /// β 4 ββ ββΆ concat β β β β βΆβ 1 ββ β βΆ sort β β β β ββΆ
- /// β 1 β β 4 β
- /// βββββββ β² β 1 β
- /// ... β β ... β
- /// β 4 β
- /// βββββββ β β 3 β
- /// β 4 β βββββββ
- /// β 3 ββ β β β β
- /// βββββββ
- /// in_mem_batches
- /// ```
- ///
- /// # Larger datasets
- ///
- /// For larger datasets, the batches are first sorted individually
- /// and then merged together.
- ///
- /// ```text
- /// βββββββ βββββββ
- /// β 2 β β 1 β
- /// β 3 β β 2 β
- /// β 1 ββ ββΆ sort β ββΆβ 2 ββ β β β β β
- /// β 4 β β 3 β
- /// β 2 β β 4 β β
- /// βββββββ βββββββ sorted output
- /// βββββββ βββββββ βΌ stream
- /// β 1 β β 1 β
- /// β 4 ββ βΆ sort β β βΆβ 1 β β β βΆ merge β β β ββΆ
- /// β 1 β β 4 β
- /// βββββββ βββββββ β²
- /// ... ... ... β
- ///
- /// βββββββ βββββββ β
- /// β 4 β β 3 β
- /// β 3 ββ βΆ sort β β βΆβ 4 ββ β β β β β
- /// βββββββ βββββββ
- ///
- /// in_mem_batches
+ /// sorted_runs[0] sorted_runs[1]
+ /// βββββββ βββββββ βββββββ βββββββ
+ /// β 1,2 β β 3,4 β β 1,3 β β 5,7 β
+ /// ββββ¬βββ ββββ¬βββ ββββ¬βββ ββββ¬βββ
+ /// βββββ¬ββββ βββββ¬ββββ
+ /// βΌ βΌ
+ /// stream 0 β β β β β β ββΆ merge ββ β β stream 1
+ /// β
+ /// βΌ
+ /// sorted output stream
/// ```
- fn in_mem_sort_stream(
+ fn merge_sorted_runs(
&mut self,
metrics: BaselineMetrics,
) -> Result<SendableRecordBatchStream> {
- if self.in_mem_batches.is_empty() {
+ let all_runs = std::mem::take(&mut self.sorted_runs);
+ self.sorted_runs_memory = 0;
+
+ if all_runs.is_empty() {
return Ok(Box::pin(EmptyRecordBatchStream::new(Arc::clone(
&self.schema,
))));
}
- // The elapsed compute timer is updated when the value is dropped.
- // There is no need for an explicit call to drop.
let elapsed_compute = metrics.elapsed_compute().clone();
let _timer = elapsed_compute.timer();
- // Please pay attention that any operation inside of `in_mem_sort_stream` will
- // not perform any memory reservation. This is for avoiding the need of handling
- // reservation failure and spilling in the middle of the sort/merge. The memory
- // space for batches produced by the resulting stream will be reserved by the
- // consumer of the stream.
-
- if self.in_mem_batches.len() == 1 {
- let batch = self.in_mem_batches.swap_remove(0);
+ // Single run: stream the chunks directly, no merge needed
+ if all_runs.len() == 1 {
+ let run = all_runs.into_iter().next().unwrap();
let reservation = self.reservation.take();
- return self.sort_batch_stream(batch, &metrics, reservation);
- }
-
- // If less than sort_in_place_threshold_bytes, concatenate and sort in place
- if self.reservation.size() < self.sort_in_place_threshold_bytes {
- // Concatenate memory batches together and sort
- let batch = concat_batches(&self.schema, &self.in_mem_batches)?;
- self.in_mem_batches.clear();
- self.reservation
- .try_resize(get_reserved_bytes_for_record_batch(&batch)?)
- .map_err(Self::err_with_oom_context)?;
- let reservation = self.reservation.take();
- return self.sort_batch_stream(batch, &metrics, reservation);
- }
-
- let streams = std::mem::take(&mut self.in_mem_batches)
+ let schema = Arc::clone(&self.schema);
+ let output_rows = metrics.output_rows().clone();
+ let stream =
+ futures::stream::iter(run.into_iter().map(Ok)).map(move |batch| {
+ match batch {
+ Ok(batch) => {
+ output_rows.add(batch.num_rows());
+ Ok(batch)
+ }
+ Err(e) => Err(e),
+ }
+ });
+ return Ok(Box::pin(ReservationStream::new(
+ Arc::clone(&schema),
+ Box::pin(RecordBatchStreamAdapter::new(schema, stream)),
+ reservation,
+ )));
+ }
+
+ // Multiple runs: create one stream per run and merge.
+ //
+ // Memory model for the multi-run merge:
+ // - self.reservation holds the sorted run data. It stays allocated
+ // for the lifetime of the ExternalSorter (freed on drop). This
+ // over-reserves as runs are consumed, but is conservative/safe.
+ // - The merge cursor (RowCursorStream/FieldCursorStream) allocates
+ // from a new_empty() reservation, drawing from pool headroom
+ // freed by merge_reservation.free() in the caller.
+ // - This works because sort() only enters this path when
+ // merge_reservation > 0, guaranteeing pool headroom for cursors.
+ // When merge_reservation == 0, sort() takes the spill path instead.
+ let streams = all_runs
Review Comment:
if i'm not mistaken merge_sorted_runs() is also being called on the non-spill path inside `sort()` when `self.spilled_before()` evaluates to false, where merge_reservation is never pre-reserved.
maybe we can make the comment more descriptive on the different headroom reliance of the different paths?
##########
datafusion/physical-plan/src/sorts/sort.rs:
##########
@@ -323,56 +285,188 @@ impl ExternalSorter {
self.reserve_memory_for_batch_and_maybe_spill(&input)
.await?;
- self.in_mem_batches.push(input);
+ let coalescer = self
+ .coalescer
+ .as_mut()
+ .expect("coalescer must exist during insert phase");
+ coalescer
+ .push_batch(input)
+ .map_err(|e| DataFusionError::ArrowError(Box::new(e), None))?;
+
+ self.drain_completed_batches()?;
+
+ Ok(())
+ }
+
+ /// Drains completed (full) batches from the coalescer, sorts each,
+ /// and appends the sorted chunks to `sorted_runs`.
+ fn drain_completed_batches(&mut self) -> Result<()> {
+ // Collect completed batches first to avoid borrow conflict
+ let mut completed = vec![];
+ if let Some(coalescer) = self.coalescer.as_mut() {
+ while let Some(batch) = coalescer.next_completed_batch() {
+ completed.push(batch);
+ }
+ }
+ for batch in &completed {
+ self.sort_and_store_run(batch)?;
+ }
+ Ok(())
+ }
+
+ /// Sorts a single coalesced batch and stores the result as a new run.
+ /// Output is chunked back to `batch_size`.
+ fn sort_and_store_run(&mut self, batch: &RecordBatch) -> Result<()> {
+ let sorted_chunks = sort_batch_chunked(batch, &self.expr, self.batch_size)?;
+
+ // After take(), StringView arrays may reference shared buffers from
+ // multiple coalesced input batches, inflating reported memory size.
+ // GC compacts them so reservation tracking stays accurate.
+ let sorted_chunks = Self::gc_stringview_batches(sorted_chunks)?;
+
+ let run_size: usize =
+ sorted_chunks.iter().map(get_record_batch_memory_size).sum();
+
+ self.sorted_runs.push(sorted_chunks);
+ self.sorted_runs_memory += run_size;
+
+ // Align the pool reservation to match actual sorted run memory.
+ //
+ // Before sorting we reserve 2x the input batch size (space for
+ // both the unsorted input and the sorted output). After sorting
+ // we drop the input, so normally sorted_runs_memory < reservation
+ // and we shrink to free the excess back to the pool.
+ //
+ // The grow path handles a rare edge case: for very small batches
+ // (single-digit rows), Arrow's per-column buffer minimums (64
+ // bytes each) can make the sorted output slightly larger than
+ // the reservation. We use grow() rather than try_grow() because:
+ //
+ // 1. The memory is already allocated β the sorted run exists
+ // in self.sorted_runs. This is accounting catch-up, not a
+ // new allocation request.
+ // 2. Under-reporting is worse than over-reporting. If we
+ // swallowed a try_grow() failure, the pool would think
+ // there is free headroom that doesn't actually exist,
+ // which could cause other operators to over-allocate and
+ // trigger a real OOM.
+ // 3. The overshoot is small and bounded: it is at most the
+ // per-column buffer overhead for a handful of rows, which
+ // is tens of KB even with wide schemas.
+ let reservation_size = self.reservation.size();
+ if reservation_size > self.sorted_runs_memory {
+ self.reservation
+ .shrink(reservation_size - self.sorted_runs_memory);
+ } else if self.sorted_runs_memory > reservation_size {
+ self.reservation
+ .grow(self.sorted_runs_memory - reservation_size);
+ }
+
+ debug_assert_eq!(
+ self.reservation.size(),
+ self.sorted_runs_memory,
+ "reservation should track sorted_runs_memory after adjustment"
+ );
+
+ Ok(())
+ }
+
+ /// Compact StringView arrays in sorted batches to eliminate shared
+ /// buffer references from `take()`. Skips work if no StringView columns.
+ fn gc_stringview_batches(batches: Vec<RecordBatch>) -> Result<Vec<RecordBatch>> {
+ // Fast path: check schema for any StringView columns
+ if let Some(first) = batches.first() {
+ let has_stringview = first.schema().fields().iter().any(|f| {
+ matches!(f.data_type(), DataType::Utf8View | DataType::BinaryView)
+ });
+ if !has_stringview {
+ return Ok(batches);
+ }
+ }
+
+ let mut result = Vec::with_capacity(batches.len());
+ for batch in batches {
+ let mut new_columns: Vec<Arc<dyn Array>> =
+ Vec::with_capacity(batch.num_columns());
+ let mut mutated = false;
+ for array in batch.columns() {
+ if let Some(sv) = array.as_any().downcast_ref::<StringViewArray>() {
+ new_columns.push(Arc::new(sv.gc()));
+ mutated = true;
+ } else {
+ new_columns.push(Arc::clone(array));
+ }
+ }
+ if mutated {
+ result.push(RecordBatch::try_new(batch.schema(), new_columns)?);
+ } else {
+ result.push(batch);
+ }
+ }
+ Ok(result)
+ }
+
+ /// Flushes any partially accumulated rows from the coalescer, sorts them,
+ /// and stores as a run. Called before spilling and at sort() time.
+ fn flush_coalescer(&mut self) -> Result<()> {
+ if let Some(coalescer) = self.coalescer.as_mut() {
+ coalescer
+ .finish_buffered_batch()
+ .map_err(|e| DataFusionError::ArrowError(Box::new(e), None))?;
+ self.drain_completed_batches()?;
+ }
Ok(())
}
fn spilled_before(&self) -> bool {
!self.finished_spill_files.is_empty()
}
+ /// Returns true if there are sorted runs in memory.
+ fn has_sorted_runs(&self) -> bool {
+ !self.sorted_runs.is_empty()
+ }
+
/// Returns the final sorted output of all batches inserted via
/// [`Self::insert_batch`] as a stream of [`RecordBatch`]es.
///
/// This process could either be:
///
- /// 1. An in-memory sort/merge (if the input fit in memory)
+ /// 1. An in-memory merge of sorted runs (if the input fit in memory)
///
- /// 2. A combined streaming merge incorporating both in-memory
- /// batches and data from spill files on disk.
+ /// 2. A combined streaming merge incorporating sorted runs
+ /// and data from spill files on disk.
async fn sort(&mut self) -> Result<SendableRecordBatchStream> {
+ self.flush_coalescer()?;
+ self.coalescer = None;
+
+ // If we spilled during the insert phase, some data is on disk
+ // and we must take the merge-from-disk path. Otherwise we can
+ // merge entirely in memory.
if self.spilled_before() {
- // Sort `in_mem_batches` and spill it first. If there are many
- // `in_mem_batches` and the memory limit is almost reached, merging
- // them with the spilled files at the same time might cause OOM.
- if !self.in_mem_batches.is_empty() {
- self.sort_and_spill_in_mem_batches().await?;
+ // Spill remaining sorted runs. Since runs are already sorted,
+ // each is written directly as its own spill file (no merge needed).
+ if self.has_sorted_runs() {
+ self.spill_sorted_runs().await?;
}
- // Transfer the pre-reserved merge memory to the streaming merge
- // using `take()` instead of `new_empty()`. This ensures the merge
- // stream starts with `sort_spill_reservation_bytes` already
- // allocated, preventing starvation when concurrent sort partitions
- // compete for pool memory. `take()` moves the bytes atomically
- // without releasing them back to the pool, so other partitions
- // cannot race to consume the freed memory.
Review Comment:
This comment is quite useful, maybe we should keep it, could help future developers know why take is being used!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich closed pull request #21629: perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in
URL: https://github.com/apache/datafusion/pull/21629
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246870829
run benchmark tpcds tpch_sort
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#discussion_r3088501037
##########
datafusion/physical-plan/src/sorts/sort.rs:
##########
@@ -95,116 +93,76 @@ impl ExternalSorterMetrics {
///
/// # Algorithm
///
-/// 1. get a non-empty new batch from input
+/// Incoming batches are coalesced via [`BatchCoalescer`] to
+/// `sort_coalesce_target_rows` (default 32768) before sorting. This
+/// reduces merge fan-in by producing fewer, larger sorted runs.
///
-/// 2. check with the memory manager there is sufficient space to
-/// buffer the batch in memory.
+/// Each coalesced batch is sorted immediately and stored as a
+/// pre-sorted run.
///
-/// 2.1 if memory is sufficient, buffer batch in memory, go to 1.
+/// 1. For each incoming batch:
+/// - Reserve memory (2x batch size). If reservation fails, flush
+/// the coalescer, spill all sorted runs to disk, then retry.
+/// - Push batch into the coalescer.
+/// - If the coalescer reached its target: sort the coalesced batch
+/// and store as a new sorted run.
///
-/// 2.2 if no more memory is available, sort all buffered batches and
-/// spill to file. buffer the next batch in memory, go to 1.
-///
-/// 3. when input is exhausted, merge all in memory batches and spills
-/// to get a total order.
+/// 2. When input is exhausted, merge all sorted runs (and any spill
+/// files) to produce a total order.
///
/// # When data fits in available memory
///
-/// If there is sufficient memory, data is sorted in memory to produce the output
+/// Sorted runs are merged in memory using a loser-tree k-way merge
+/// (via [`StreamingMergeBuilder`]).
///
/// ```text
-/// βββββββ
-/// β 2 β
-/// β 3 β
-/// β 1 ββ β β β β β β β β β
-/// β 4 β
-/// β 2 β β
-/// βββββββ βΌ
-/// βββββββ
-/// β 1 β In memory
-/// β 4 ββ β β β β ββΆ sort/merge β β β β ββΆ total sorted output
-/// β 1 β
-/// βββββββ β²
-/// ... β
-///
-/// βββββββ β
-/// β 4 β
-/// β 3 ββ β β β β β β β β β
-/// βββββββ
-///
-/// in_mem_batches
+/// ββββββββββββ ββββββββββββββ ββββββββ ββββββββββββββ
+/// β Incoming ββββββΆβ Batch ββββββΆβ Sort ββββββΆβ Sorted Run β
+/// β Batches β β Coalescer β β β β (in memory)β
+/// ββββββββββββ ββββββββββββββ ββββββββ βββββββ¬βββββββ
+/// β
+/// ββββββββββββββββ
+/// βΌ
+/// k-way merge (loser tree)
+/// β
+/// βΌ
+/// total sorted output
/// ```
///
/// # When data does not fit in available memory
///
-/// When memory is exhausted, data is first sorted and written to one
-/// or more spill files on disk:
-///
-/// ```text
-/// βββββββ .βββββββββββββββββ.
-/// β 2 β ( )
-/// β 3 β β`βββββββββββββββββ'β
-/// β 1 ββ β β β β β β β ββββββ β
-/// β 4 β β β β 1 ββ β
-/// β 2 β β β... ββ β
-/// βββββββ βΌ β β 4 ββ β β β β
-/// βββββββ β βββββββ 1 ββ β
-/// β 1 β In memory β ββββββ β ββ β
-/// β 4 ββ β βΆ sort/merge β β β β βΌ β β β β ββΆ ... ββ β
-/// β 1 β and write to file β β ββ β
-/// βββββββ β 4 ββ β
-/// ... β² β βββββββ β
-/// β β ββββββ β
-/// βββββββ β.βββββββββββββββββ.β
-/// β 4 β β ( )
-/// β 3 ββ β β β β β β `βββββββββββββββββ'
-/// βββββββ
-///
-/// in_mem_batches spills
-/// (file on disk in Arrow
-/// IPC format)
-/// ```
-///
-/// Once the input is completely read, the spill files are read and
-/// merged with any in memory batches to produce a single total sorted
-/// output:
+/// When memory is exhausted, sorted runs are spilled directly to disk
+/// (one spill file per run β no merge needed since runs are already
+/// sorted). `MultiLevelMergeBuilder` handles the final merge from disk
+/// with dynamic fan-in.
///
/// ```text
-/// .βββββββββββββββββ.
-/// ( )
-/// β`βββββββββββββββββ'β
-/// β ββββββ β
-/// β β 1 ββ β
-/// β β... ββ β β β β βββ β β β β β
-/// β β 4 ββ ββββββ β β
-/// β βββββββ β 1 ββ β βΌ
-/// β ββββββ β ββ β
-/// β β... ββ βββ β β βΆ merge β β ββΆ total sorted output
-/// β β ββ β
-/// β β 4 ββ β β²
-/// β βββββββ β β
-/// β ββββββ β
-/// β.βββββββββββββββββ.β β
-/// ( )
-/// `βββββββββββββββββ' β
-/// spills
+/// ββββββββββββ ββββββββββββββ ββββββββ ββββββββββββββ
+/// β Incoming ββββββΆβ Batch ββββββΆβ Sort ββββββΆβ Sorted Run β
Review Comment:
In the current approach, it would be worth it to "push down" the target batch size to the inner coalescer (if any), so e.g. the output of the previous stage already is of the higher batch size instead of doing another copy.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4255675609
π€ Criterion benchmark running (GKE) | [trigger](https://github.com/apache/datafusion/pull/21629#issuecomment-4255649635)
**Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB) | `Linux bench-c4255649635-1332-2jl79 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux`
<details><summary>CPU Details (lscpu)</summary>
```
Architecture: aarch64
CPU op-mode(s): 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: ARM
Model name: Neoverse-V2
Model: 1
Thread(s) per core: 1
Core(s) per cluster: 16
Socket(s): -
Cluster(s): 1
Stepping: r0p1
BogoMIPS: 2000.00
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache: 1 MiB (16 instances)
L1i cache: 1 MiB (16 instances)
L2 cache: 32 MiB (16 instances)
L3 cache: 80 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Mitigation; CSV2, BHB
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Not affected
```
</details>
Comparing externalsorter (01983025442464d834808a036564f709af58aaff) to 5c653be (merge-base) [diff](https://github.com/apache/datafusion/compare/5c653bee5da64003915f6dfeb3da15759b091a8d..01983025442464d834808a036564f709af58aaff)
BENCH_NAME=sort
BENCH_COMMAND=cargo bench --features=parquet --bench sort
BENCH_FILTER=
Results will be posted here when complete
---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4262519681
More brainstorming with Claude:
> ### Proposed fix
>
> Don't coalesce schemas that have variable-length non-view columns (StringArray, BinaryArray, LargeStringArray, LargeBinaryArray, DictionaryArray with string/binary values). For these schemas, set the coalesce target to `batch_size` instead of `sort_coalesce_target_rows`:
>
> - Full-size batches pass through uncoalesced and sort individually, same as `main` β no regression
> - Small batches (from filters, joins, pushdown) coalesce up to `batch_size` only β some fan-in reduction without blowing cache
> - StringView and fixed-width schemas keep the full 32K coalesce target and retain all speedups
>
> Fan-in reduction is the price we pay for StringArray schemas. We can't optimize the merge if the sort itself is 2.5x slower getting there.
>
> Comet does not support StringView β all string columns use StringArray, so this regression directly affects Comet workloads.
>
> ### Why check all columns, not just sort keys?
>
> `take` reorders all columns in the batch, not just sort keys. Wide schemas (e.g. small string key + 70KB string value) are especially vulnerable β coalescing to 32K means `take` scatter-gathers across ~2.2GB of value data.
>
> ### Alternatives considered
>
> **Smaller intermediate target (e.g. 16K):** Any coalescing beyond `batch_size` amplifies cache pressure for wide schemas proportionally. No clear sweet spot.
>
> **Convert StringArray β StringView before take:** The gather (conversion) is cheap and `take` on views is cheap, but the resulting views point to the original unsorted buffer. No memory freed until the entire buffer drops β ~2x memory bloat, wrong tradeoff for a spilling sort.
>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4261197731
Marking as draft while we explore performance trade-offs. I don't want to accidentally merge this yet.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#discussion_r3088547619
##########
datafusion/physical-plan/src/sorts/sort.rs:
##########
@@ -323,56 +285,188 @@ impl ExternalSorter {
self.reserve_memory_for_batch_and_maybe_spill(&input)
.await?;
- self.in_mem_batches.push(input);
+ let coalescer = self
+ .coalescer
+ .as_mut()
+ .expect("coalescer must exist during insert phase");
+ coalescer
+ .push_batch(input)
+ .map_err(|e| DataFusionError::ArrowError(Box::new(e), None))?;
+
+ self.drain_completed_batches()?;
+
+ Ok(())
+ }
+
+ /// Drains completed (full) batches from the coalescer, sorts each,
+ /// and appends the sorted chunks to `sorted_runs`.
+ fn drain_completed_batches(&mut self) -> Result<()> {
+ // Collect completed batches first to avoid borrow conflict
+ let mut completed = vec![];
+ if let Some(coalescer) = self.coalescer.as_mut() {
+ while let Some(batch) = coalescer.next_completed_batch() {
+ completed.push(batch);
+ }
+ }
+ for batch in &completed {
+ self.sort_and_store_run(batch)?;
Review Comment:
Nice - I wonder if a part of the speedup comes from this, sorting batch immediately (while in CPU cache) instead of waiting to the end.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246749034
π€ Benchmark running (GKE) | [trigger](https://github.com/apache/datafusion/pull/21629#issuecomment-4246734700)
**Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB) | `Linux bench-c4246734700-1255-84ftb 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux`
<details><summary>CPU Details (lscpu)</summary>
```
Architecture: aarch64
CPU op-mode(s): 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: ARM
Model name: Neoverse-V2
Model: 1
Thread(s) per core: 1
Core(s) per cluster: 16
Socket(s): -
Cluster(s): 1
Stepping: r0p1
BogoMIPS: 2000.00
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache: 1 MiB (16 instances)
L1i cache: 1 MiB (16 instances)
L2 cache: 32 MiB (16 instances)
L3 cache: 80 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Mitigation; CSV2, BHB
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Not affected
```
</details>
Comparing externalsorter (32a688271e2c9cb67b47454a2bc72f3cb926cfee) to e6b32fe (merge-base) [diff](https://github.com/apache/datafusion/compare/e6b32fe66b4e8e313ff79a9c45585d1a4bc2a19e..32a688271e2c9cb67b47454a2bc72f3cb926cfee) using: tpch10
Results will be posted here when complete
---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246885961
π€ Benchmark running (GKE) | [trigger](https://github.com/apache/datafusion/pull/21629#issuecomment-4246870829)
**Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB) | `Linux bench-c4246870829-1256-zqlsf 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux`
<details><summary>CPU Details (lscpu)</summary>
```
Architecture: aarch64
CPU op-mode(s): 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: ARM
Model name: Neoverse-V2
Model: 1
Thread(s) per core: 1
Core(s) per cluster: 16
Socket(s): -
Cluster(s): 1
Stepping: r0p1
BogoMIPS: 2000.00
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache: 1 MiB (16 instances)
L1i cache: 1 MiB (16 instances)
L2 cache: 32 MiB (16 instances)
L3 cache: 80 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Mitigation; CSV2, BHB
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Not affected
```
</details>
Comparing externalsorter (32a688271e2c9cb67b47454a2bc72f3cb926cfee) to e6b32fe (merge-base) [diff](https://github.com/apache/datafusion/compare/e6b32fe66b4e8e313ff79a9c45585d1a4bc2a19e..32a688271e2c9cb67b47454a2bc72f3cb926cfee) using: tpcds
Results will be posted here when complete
---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4246806188
π€ Benchmark completed (GKE) | [trigger](https://github.com/apache/datafusion/pull/21629#issuecomment-4246734700)
**Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB)
<details><summary>CPU Details (lscpu)</summary>
```
Architecture: aarch64
CPU op-mode(s): 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: ARM
Model name: Neoverse-V2
Model: 1
Thread(s) per core: 1
Core(s) per cluster: 16
Socket(s): -
Cluster(s): 1
Stepping: r0p1
BogoMIPS: 2000.00
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache: 1 MiB (16 instances)
L1i cache: 1 MiB (16 instances)
L2 cache: 32 MiB (16 instances)
L3 cache: 80 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Mitigation; CSV2, BHB
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Not affected
```
</details>
<details><summary>Details</summary>
<p>
```
Comparing HEAD and externalsorter
--------------------
Benchmark tpch_sf10.json
--------------------
βββββββββββββ³βββββββββββββββββββββββββββββββββββββ³βββββββββββββββββββββββββββββββββββββ³βββββββββββββββ
β Query β HEAD β externalsorter β Change β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β QQuery 1 β 371.99 / 376.96 Β±2.69 / 379.67 ms β 373.11 / 374.56 Β±0.99 / 376.21 ms β no change β
β QQuery 2 β 136.84 / 139.64 Β±2.41 / 142.60 ms β 137.37 / 141.53 Β±3.83 / 148.61 ms β no change β
β QQuery 3 β 290.81 / 297.53 Β±3.84 / 301.08 ms β 294.21 / 297.24 Β±2.49 / 301.82 ms β no change β
β QQuery 4 β 157.06 / 158.25 Β±1.04 / 160.18 ms β 163.17 / 163.98 Β±0.65 / 164.88 ms β no change β
β QQuery 5 β 428.84 / 434.96 Β±5.27 / 444.66 ms β 451.75 / 457.04 Β±4.95 / 464.64 ms β 1.05x slower β
β QQuery 6 β 132.66 / 134.17 Β±1.23 / 135.89 ms β 133.50 / 134.61 Β±0.86 / 135.48 ms β no change β
β QQuery 7 β 563.02 / 587.09 Β±15.45 / 606.59 ms β 587.86 / 594.62 Β±4.33 / 599.57 ms β no change β
β QQuery 8 β 483.62 / 492.86 Β±7.21 / 503.79 ms β 478.84 / 491.04 Β±9.87 / 506.50 ms β no change β
β QQuery 9 β 707.85 / 714.91 Β±6.70 / 724.34 ms β 669.57 / 691.14 Β±14.47 / 708.41 ms β no change β
β QQuery 10 β 333.70 / 347.25 Β±7.06 / 354.05 ms β 340.97 / 354.39 Β±10.48 / 368.41 ms β no change β
β QQuery 11 β 104.30 / 112.04 Β±5.42 / 119.20 ms β 110.99 / 115.85 Β±3.85 / 122.81 ms β no change β
β QQuery 12 β 202.29 / 204.71 Β±2.28 / 208.32 ms β 208.39 / 209.76 Β±1.29 / 212.04 ms β no change β
β QQuery 13 β 305.63 / 319.39 Β±7.94 / 328.85 ms β 309.99 / 315.73 Β±6.53 / 327.63 ms β no change β
β QQuery 14 β 180.75 / 182.10 Β±0.99 / 183.64 ms β 181.13 / 182.52 Β±1.44 / 185.24 ms β no change β
β QQuery 15 β 338.13 / 342.58 Β±2.38 / 345.31 ms β 331.27 / 333.51 Β±2.16 / 337.52 ms β no change β
β QQuery 16 β 88.02 / 90.32 Β±1.74 / 92.47 ms β 84.29 / 86.72 Β±2.30 / 89.96 ms β no change β
β QQuery 17 β 771.91 / 803.56 Β±18.47 / 824.96 ms β 762.20 / 794.23 Β±16.25 / 806.51 ms β no change β
β QQuery 18 β 863.78 / 873.82 Β±11.69 / 895.72 ms β 869.91 / 920.79 Β±38.92 / 970.84 ms β 1.05x slower β
β QQuery 19 β 266.58 / 269.95 Β±3.31 / 276.21 ms β 272.78 / 279.70 Β±6.65 / 288.50 ms β no change β
β QQuery 20 β 320.19 / 327.34 Β±5.56 / 335.30 ms β 333.41 / 339.49 Β±5.65 / 348.05 ms β no change β
β QQuery 21 β 869.13 / 876.28 Β±5.06 / 882.58 ms β 848.74 / 859.56 Β±14.49 / 887.53 ms β no change β
β QQuery 22 β 78.97 / 81.54 Β±2.08 / 85.14 ms β 82.82 / 85.25 Β±2.54 / 88.65 ms β no change β
βββββββββββββ΄βββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββ΄βββββββββββββββ
βββββββββββββββββββββββββββββββββ³ββββββββββββ
β Benchmark Summary β β
β‘ββββββββββββββββββββββββββββββββββββββββββββ©
β Total Time (HEAD) β 8167.27ms β
β Total Time (externalsorter) β 8223.26ms β
β Average Time (HEAD) β 371.24ms β
β Average Time (externalsorter) β 373.78ms β
β Queries Faster β 0 β
β Queries Slower β 2 β
β Queries with No Change β 20 β
β Queries with Failure β 0 β
βββββββββββββββββββββββββββββββββ΄ββββββββββββ
```
</p>
</details>
<details><summary>Resource Usage</summary>
**tpch10 β base (merge-base)**
| Metric | Value |
|--------|-------|
| Wall time | 41.2s |
| Peak memory | 10.2 GiB |
| Avg memory | 7.8 GiB |
| CPU user | 434.7s |
| CPU sys | 26.4s |
| Peak spill | 0 B |
**tpch10 β branch**
| Metric | Value |
|--------|-------|
| Wall time | 41.5s |
| Peak memory | 9.6 GiB |
| Avg memory | 7.5 GiB |
| CPU user | 436.0s |
| CPU sys | 27.4s |
| Peak spill | 0 B |
</details>
---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#discussion_r3081762076
##########
datafusion/common/src/config.rs:
##########
@@ -555,7 +555,17 @@ config_namespace! {
/// When sorting, below what size should data be concatenated
/// and sorted in a single RecordBatch rather than sorted in
/// batches and merged.
- pub sort_in_place_threshold_bytes: usize, default = 1024 * 1024
+ ///
+ /// Deprecated: this option is no longer used. The sort pipeline
+ /// now always coalesces batches before sorting. Use
+ /// `sort_coalesce_target_rows` instead.
+ pub sort_in_place_threshold_bytes: usize, warn = "`sort_in_place_threshold_bytes` is deprecated and ignored. Use `sort_coalesce_target_rows` instead.", default = 1024 * 1024
+
+ /// Target number of rows to coalesce before sorting in ExternalSorter.
+ ///
+ /// Larger values reduce merge fan-in by producing fewer, larger
+ /// sorted runs.
+ pub sort_coalesce_target_rows: usize, default = 32768
Review Comment:
I wonder if we can make this somewhat adaptive: as we usually load everything in memory, it seems for very large sets larger batches would be even more favorable (e.g. use 10MiB "scratch space" for coalescing instead of 32KiB rows would make sense if our data is 1GiB and perhaps be even faster?)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Coalesce batches before sorting in ExternalSorter to reduce merge fan-in [datafusion]
Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#issuecomment-4253363299
π€ Criterion benchmark running (GKE) | [trigger](https://github.com/apache/datafusion/pull/21629#issuecomment-4253348811)
**Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB) | `Linux bench-c4253348811-1301-2rfg4 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux`
<details><summary>CPU Details (lscpu)</summary>
```
Architecture: aarch64
CPU op-mode(s): 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: ARM
Model name: Neoverse-V2
Model: 1
Thread(s) per core: 1
Core(s) per cluster: 16
Socket(s): -
Cluster(s): 1
Stepping: r0p1
BogoMIPS: 2000.00
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache: 1 MiB (16 instances)
L1i cache: 1 MiB (16 instances)
L2 cache: 32 MiB (16 instances)
L3 cache: 80 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Mitigation; CSV2, BHB
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Not affected
```
</details>
Comparing externalsorter (689dfd2ad59416ddb75f8cc691ae787271da7805) to d0692b8 (merge-base) [diff](https://github.com/apache/datafusion/compare/d0692b8ee999ed72cd2a8f7000884618adfc06ee..689dfd2ad59416ddb75f8cc691ae787271da7805)
BENCH_NAME=sort
BENCH_COMMAND=cargo bench --features=parquet --bench sort
BENCH_FILTER=
Results will be posted here when complete
---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org