Skip to content

Perf: Improve dictionary slice concatenation - #12008

Open
Rich-T-kid wants to merge 1 commit into
apache:mainfrom
Rich-T-kid:codex/dictionary-concat-slices
Open

Rich-T-kid wants to merge 1 commit into
apache:mainfrom
Rich-T-kid:codex/dictionary-concat-slices

Conversation

@Rich-T-kid

@Rich-T-kid Rich-T-kid commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #11885

Why is this change needed?

Slicing a dictionary array only slices its keys; it still retains the full values array. When concat or interleave merges short slices from large dictionaries, the current code builds a mask and key mapping for every dictionary value, including values that no selected row references. The work therefore scales with the full dictionary instead of the number of output rows.

What changes are included in this PR?

When a dictionary has more than 16 values per selected row, collect only the referenced keys and store the old-to-new key mappings sparsely. Smaller dictionaries continue using the existing dense mask and vector mapping. Both concat and interleave use this shared dictionary merge path.

Are these changes tested?

Tests cover concat and interleave of short slices backed by large dictionaries, sparse key remapping, null keys, and the existing dense path.

The consolidated benchmark coverage, including the ratio sweep for evaluating the 16x cutoff, is in #12054.

Are there any significant user-facing changes?

No. This only changes how dictionary values are merged internally.

@github-actions github-actions Bot added arrow-kernels Crates that transform arrow data (e.g. compute, cast) enhancement New feature/addition labels Oct 31, 2026
@alamb

alamb commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

run benchmark concatenate_kernels

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: concatenate_kernels

Sharding factor: 1 (1 workers).

Comparing codex/dictionary-concat-slices (90cbf31) to bf0cde3 (merge-base) diff

Run configuration
run benchmark concatenate_kernels
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark failed or incomplete (GKE) | trigger

Target: concatenate_kernels

Comparing codex/dictionary-concat-slices (90cbf31) to bf0cde3 (merge-base) diff

Run configuration
run benchmark concatenate_kernels
shards: 1
Errors / missing shards
concatenate_kernels — shard 1/1: Benchmark for [this request](https://github.com/apache/arrow-rs/pull/12008#issuecomment-6542803016) failed before finishing (Kubernetes reason: `BackoffLimitExceeded`).

Benchmarks requested: `concatenate_kernels`

<details><summary>Runner log (last 40 lines)</summary>

```
2026-10-31T11:32:05.124686Z  INFO runner starting benchmark runner bench_type=ArrowCriterion, pr_url=https://github.com/apache/arrow-rs/pull/12008, benchmarks=concatenate_kernels
2026-10-31T11:32:05.379459Z  INFO benchmark_controller::runner::bench_arrow === Cloning PR branch ===
2026-10-31T11:32:05.379476Z  INFO benchmark_controller::runner::shell running command cmd=git, args=["clone", "--depth=200", "https://github.com/apache/arrow-rs.git", "/workspace/arrow-rs-branch"], cwd="/"
2026-10-31T11:32:10.389052Z  INFO benchmark_controller::runner::shell running command cmd=git, args=["fetch", "--depth=1", "origin", "90cbf31cd8dbacb5ae12566c5206624961461f90"], cwd="/workspace/arrow-rs-branch"
2026-10-31T11:32:15.390775Z  INFO benchmark_controller::runner::shell running command cmd=git, args=["-c", "advice.detachedHead=false", "checkout", "90cbf31cd8dbacb5ae12566c5206624961461f90"], cwd="/workspace/arrow-rs-branch"
2026-10-31T11:32:20.392795Z  INFO benchmark_controller::runner::shell running command cmd=git, args=["rev-parse", "HEAD"], cwd="/workspace/arrow-rs-branch"
2026-10-31T11:32:25.395190Z  INFO benchmark_controller::runner::shell running command cmd=git, args=["submodule", "update", "--init"], cwd="/workspace/arrow-rs-branch"
2026-10-31T11:32:30.397236Z  INFO benchmark_controller::runner::shell running command cmd=cargo, args=["update"], cwd="/workspace/arrow-rs-branch"
2026-10-31T11:32:35.399401Z  INFO benchmark_controller::runner::bench_arrow === Cloning merge-base ===
2026-10-31T11:32:35.399418Z  INFO benchmark_controller::runner::shell running command cmd=git, args=["clone", "--depth=200", "https://github.com/apache/arrow-rs.git", "/workspace/arrow-rs-base"], cwd="/"
2026-10-31T11:32:40.402025Z  INFO benchmark_controller::runner::shell running command cmd=git, args=["fetch", "--depth=1", "origin", "bf0cde345b14e5abdf3e8abb57f55d43da48b49f"], cwd="/workspace/arrow-rs-base"
2026-10-31T11:32:45.404052Z  INFO benchmark_controller::runner::shell running command cmd=git, args=["-c", "advice.detachedHead=false", "checkout", "bf0cde345b14e5abdf3e8abb57f55d43da48b49f"], cwd="/workspace/arrow-rs-base"
2026-10-31T11:32:50.406196Z  INFO benchmark_controller::runner::shell running command cmd=git, args=["rev-parse", "HEAD"], cwd="/workspace/arrow-rs-base"
2026-10-31T11:32:55.408405Z  INFO benchmark_controller::runner::shell running command cmd=git, args=["submodule", "update", "--init"], cwd="/workspace/arrow-rs-base"
2026-10-31T11:33:00.410560Z  INFO benchmark_controller::runner::shell running command cmd=cargo, args=["update"], cwd="/workspace/arrow-rs-base"
2026-10-31T11:33:05.412889Z  INFO benchmark_controller::runner::shell running command cmd=rustc, args=["--version"], cwd="/"
2026-10-31T11:33:10.415632Z  INFO benchmark_controller::runner::bench_arrow === Compiling PR branch and merge-base in parallel ===
2026-10-31T11:33:12.166669Z ERROR runner benchmark failed error=branch build failed: cargo bench --features=arrow,async,test_common,experimental,object_store --bench concatenate_kernels --no-run exited with code 101
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
error: no bench target named `concatenate_kernels` in default-run packages

help: a target with a similar name exists: `concatenate_kernel`
```

</details>

<details><summary>Kubernetes message</summary>

```
Job has reached the specified backoff limit
```

</details>

---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
Per-runner information
concatenate_kernels — shard 1/1

Node: gk3-benchmark-cluster-nap-bch756b4-46b2a638-fvcz

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

uname:

Linux bench-c6542803016-4209-drhqn 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench concatenate_kernels
CPU Details (lscpu)
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
Resource Usage

No completed measurement resource samples.


File an issue against this benchmark runner

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

The controlled DataFusion end-to-end run is complete: results.

Using DataFusion #26816 with every Arrow crate pinned to either bf0cde345b14e5abdf3e8abb57f55d43da48b49f (this PR's parent) or 90cbf31cd8dbacb5ae12566c5206624961461f90 (this PR), clickbench_partitioned with dictionary reads enabled changed from 50.86 s to 40.58 s (-20.2%).

The queries expected to concatenate sliced dictionary group keys improved most:

Query Parent This PR Change
Q5 1035.92 ms 826.53 ms 1.25x
Q12 1062.14 ms 844.74 ms 1.26x
Q13 1551.81 ms 1298.19 ms 1.20x
Q14 1160.91 ms 913.46 ms 1.27x
Q16 2175.27 ms 1379.22 ms 1.58x
Q17 2172.82 ms 1386.31 ms 1.57x
Q18 3502.00 ms 2033.89 ms 1.72x
Q33 6963.34 ms 3857.07 ms 1.81x
Q34 7235.37 ms 3948.00 ms 1.83x

No spill occurred on either side.

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

should have marked this a draft

@Rich-T-kid
Rich-T-kid marked this pull request as draft October 31, 2026 23:08
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

run benchmark concatenate_kernel
env:
BENCH_FILTER: dict

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: concatenate_kernel

Sharding factor: 1 (1 workers).

Comparing codex/dictionary-concat-slices (90cbf31) to bf0cde3 (merge-base) diff

Run configuration
run benchmark concatenate_kernel
env:
  BENCH_FILTER: dict
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: concatenate_kernel

Comparing codex/dictionary-concat-slices (90cbf31) to bf0cde3 (merge-base) diff

Run configuration
run benchmark concatenate_kernel
env:
  BENCH_FILTER: dict
shards: 1
Details
group                                                   base                                   changed
-----                                                   ----                                   -------
concat str_dict 1024                                    1.02      2.1±0.01µs        ? ?/sec    1.00      2.1±0.01µs        ? ?/sec
concat str_dict_sparse 1024                             1.00      8.5±0.03µs        ? ?/sec    1.00      8.5±0.03µs        ? ?/sec
concat struct with int32 and dicts size=1024 count=2    1.00      4.7±0.03µs        ? ?/sec    1.00      4.7±0.04µs        ? ?/sec

Per-runner information
concatenate_kernel — shard 1/1

Node: gk3-benchmark-cluster-nap-1h5f9ztd-949bd8ae-9fwn

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

uname:

Linux bench-c6550485489-4215-cfp2k 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench concatenate_kernel
CPU Details (lscpu)
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
Resource Usage

base (merge-base)

Metric Value
Wall time 40.0s
Peak memory 100.1 MiB
Avg memory 75.3 MiB
CPU user 30.3s
CPU sys 0.1s
Peak spill 0 B

branch

Metric Value
Wall time 35.0s
Peak memory 130.9 MiB
Avg memory 86.8 MiB
CPU user 30.0s
CPU sys 0.0s
Peak spill 0 B

File an issue against this benchmark runner

@Rich-T-kid Rich-T-kid closed this Nov 1, 2026
@Rich-T-kid Rich-T-kid reopened this Nov 2, 2026
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

@CuteChuanChuan could you take a look

@Rich-T-kid Rich-T-kid changed the title Improve dictionary slice concatenation Perf: Improve dictionary slice concatenation Nov 3, 2026
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

I had ai run some benchmarks with this pr as the tip in datafusion and the results look good #12008 (comment). I think it may be worth adding targeted benchmarks here just so we can choose a correct threshold as 16x may be too conservative.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow-kernels Crates that transform arrow data (e.g. compute, cast) enhancement New feature/addition performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

concat of dictionary slices does work proportional to each input's whole dictionary, not its rows

3 participants