Skip to content

fix(parquet): cap byte-budget level windows by value count - #11996

Merged
etseidl merged 1 commit into
apache:mainfrom
pydantic:fix-11994-dict-overflow
Nov 3, 2026
Merged

etseidl merged 1 commit into
apache:mainfrom
pydantic:fix-11994-dict-overflow

Conversation

@adriangb

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

SubBatchStrategy::Levels turns a value budget into a level count using the chunk's average level:value ratio. That ratio says nothing about how many values a single window holds. If 28 large values come before 996 nulls, the first 37-level window contains all 28 values, so the dictionary page reaches about 2.2 GB before the spill check runs. That breaks the "at most two values per page" bound described in #10554.

What changes are included in this PR?

  • SubBatchStrategy::Levels now carries a max_values cap (twice the value budget) alongside the level count.
  • write_granular_chunk ends each level window at whichever comes first: the level count, or the point where max_values values have been seen. It reuses window_end_for_values to find that point.
  • When nulls are evenly spread the cap is never reached, so the number of mini-batches is unchanged. The throughput tradeoff from fix(parquet): cut data page byte-budget mini-batches on exact value counts #10554 still holds. The added cost is one walk over the window's def levels, and only for Materialized def levels on the granular (large-value) path.

Are these changes tested?

Yes. test_column_writer_caps_dictionary_page_size_with_clustered_nulls is a scaled-down version of the issue's reproducer: 28 distinct 64 KiB values, then 996 nulls, with a 64 KiB dictionary page limit. It fails without the cap (the dictionary page holds all 28 values) and passes with it.

Are there any user-facing changes?

No API changes. Writers with clustered nulls and large values now produce bounded pages instead of failing with Page uncompressed size overflow.

🤖 Generated with Claude Code

Ratio-sized level windows assume nulls are spread evenly through a
chunk. When values cluster ahead of a run of nulls, one window can hold
every value, so the dictionary page grows past the format's 2 GiB page
limit before its spill check runs. Cap each level window at twice the
value budget so the documented two-values-per-page bound holds for any
null layout.

Closes apache#11994

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@adriangb

Copy link
Copy Markdown
Contributor Author

run benchmark arrow_writer

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: arrow_writer

Sharding factor: 1 (1 workers).

Comparing fix-11994-dict-overflow (0336bf8) to 9ffd63d (merge-base) diff

Run configuration
run benchmark arrow_writer
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangb

Copy link
Copy Markdown
Contributor Author

@sdf-jkl wdyt?

@adriangb

Copy link
Copy Markdown
Contributor Author

run benchmark arrow_writer
shards: 4

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: arrow_writer

Sharding factor: 4 (4 workers).

Comparing fix-11994-dict-overflow (0336bf8) to 9ffd63d (merge-base) diff

Run configuration
run benchmark arrow_writer
shards: 4

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: arrow_writer

Comparing fix-11994-dict-overflow (0336bf8) to 9ffd63d (merge-base) diff

Run configuration
run benchmark arrow_writer
shards: 1
Errors / missing shards
arrow_writer — shard 1/1: Benchmark for [this request](https://github.com/apache/arrow-rs/pull/11996#issuecomment-6512736874) hit the 7200s job deadline before finishing.

Benchmarks requested: `arrow_writer`

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

```
Job was active longer than specified deadline
```

</details>

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

Node: gk3-benchmark-cluster-nap-1fzug0kq-c69560ca-b6ps

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

uname:

Linux bench-c6512736874-4130-dwhr8 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 arrow_writer
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

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: arrow_writer

Comparing fix-11994-dict-overflow (0336bf8) to 9ffd63d (merge-base) diff

Run configuration
run benchmark arrow_writer
shards: 4

Comparison results: View the complete native critcmp output.

The comparison is published in an unlisted Gist because the original inline report exceeded GitHub's comment limit.

Per-runner information
arrow_writer — shard 1/4

Node: gk3-benchmark-cluster-nap-1fzug0kq-50073869-h5nx

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

uname:

Linux bench-c6513830563-4133-bdfs6 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 arrow_writer
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 1750.4s
Peak memory 2.1 GiB
Avg memory 198.4 MiB
CPU user 1714.2s
CPU sys 30.9s
Peak spill 0 B

branch

Metric Value
Wall time 1720.4s
Peak memory 2.1 GiB
Avg memory 194.4 MiB
CPU user 1685.1s
CPU sys 30.9s
Peak spill 0 B
arrow_writer — shard 2/4

Node: gk3-benchmark-cluster-nap-jeel64w1-66f44736-l628

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

uname:

Linux bench-c6513830563-4134-jt68q 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 arrow_writer
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 1785.4s
Peak memory 2.2 GiB
Avg memory 345.9 MiB
CPU user 1735.3s
CPU sys 47.7s
Peak spill 0 B

branch

Metric Value
Wall time 1775.4s
Peak memory 2.2 GiB
Avg memory 343.5 MiB
CPU user 1724.3s
CPU sys 46.7s
Peak spill 0 B
arrow_writer — shard 3/4

Node: gk3-benchmark-cluster-nap-1fzug0kq-50073869-jzxw

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

uname:

Linux bench-c6513830563-4135-rkscs 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 arrow_writer
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 1910.4s
Peak memory 2.2 GiB
Avg memory 287.3 MiB
CPU user 1863.3s
CPU sys 41.9s
Peak spill 0 B

branch

Metric Value
Wall time 1905.4s
Peak memory 2.2 GiB
Avg memory 287.7 MiB
CPU user 1861.9s
CPU sys 39.3s
Peak spill 0 B
arrow_writer — shard 4/4

Node: gk3-benchmark-cluster-nap-1fzug0kq-c69560ca-b6ps

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

uname:

Linux bench-c6513830563-4136-pljzs 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 arrow_writer
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 1760.4s
Peak memory 2.1 GiB
Avg memory 226.3 MiB
CPU user 1724.2s
CPU sys 30.9s
Peak spill 0 B

branch

Metric Value
Wall time 1750.4s
Peak memory 2.0 GiB
Avg memory 226.9 MiB
CPU user 1716.3s
CPU sys 28.8s
Peak spill 0 B

File an issue against this benchmark runner

@adriangb

Copy link
Copy Markdown
Contributor Author

Benchmark summary:

this PR #11997
geomean (483 cases) +0.4% −0.9%
byte_array_sparse_99pct_null +4% −6.5%

The +4% comes from the new per-window cap scanning def levels; everything else is noise. #11997 removes a scan of the same def levels, so with both merged the sparse case is faster than main. Suggest merging this as is and following up with #11997.

@etseidl
etseidl self-requested a review November 2, 2026 18:50

@etseidl etseidl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @adriangb. Looking forward to #11997.

@adriangb

adriangb commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

yep, thanks for the review. LGTM and we can work on that one.

@etseidl
etseidl added this pull request to the merge queue Nov 3, 2026
Merged via the queue into apache:main with commit b231cf1 Nov 3, 2026
21 checks passed
@adriangb
adriangb deleted the fix-11994-dict-overflow branch November 3, 2026 04:07
@sdf-jkl

sdf-jkl commented Nov 4, 2026

Copy link
Copy Markdown
Member

Thanks @adriangb @etseidl

Phoenix500526 pushed a commit to Phoenix500526/arrow-rs that referenced this pull request Nov 25, 2026
…e#11997)

# Which issue does this PR close?

- Related to apache#11994 / apache#11996: this is a follow-up perf tweak, not the
fix itself.

# Rationale for this change

`ByteBudgetChunker::byte_budget_sub_batch` calls
`chunk_def.value_count(...)` before it asks the encoder whether the
chunk's values fit the page budget. For nullable columns (`Materialized`
def levels) that call is an O(chunk_size) scan, and it runs on every
chunk of every nullable byte-array column, even chunks far below the
page limit.

# What changes are included in this PR?

The chunker now asks the encoder first, about the next `chunk_size`
values. That window always contains the chunk's values as a prefix,
because a chunk holds at most `chunk_size` values.

`count_values_within_byte_budget[_gather]` counts how many *leading*
values fit, so its answer for the window also answers for the chunk:
- **The whole window fits:** the chunk fits too. Return `None` without
scanning def levels. This is the common case, and it uses the existing
stage-1 bounds. Those cost O(1) for view arrays and one ordered pass
over the indices for offset arrays.
- **The count stops at `k`, the first value that overflows:** only now
run `value_count`. If `k >= vals_in_chunk` the overflow is past this
chunk, so the chunk fits. Otherwise `k` is the same answer the current
code computes.

The lookahead is used only on the gather path (`value_indices`), which
the arrow writer always uses, because every gather index names a real
value. A contiguous `values` slice from a raw `ColumnWriter` caller may
be padded with placeholder `ByteArray`s past the values its levels
reference, and those can't be sized. That path keeps counting the
chunk's values first, as on `main`.

There are no new trait methods. An earlier revision of this PR added a
byte-array-only `values_fit_within_byte_budget_gather` hook to
`ColumnValueEncoder`. This version reuses the existing count instead,
and benchmarked the same.

# Are these changes tested?

New unit tests in `byte_budget_chunker` call `pick_sub_batch` directly,
through both the contiguous and the gather entry points:
- a small chunk is not split;
- an overflow past the chunk, inside the lookahead window, does not
split it;
- an overflow inside the chunk splits it, with the same `Levels` window
as on `main`;
- an all-null chunk is not split;
- a contiguous slice padded with placeholder values past the chunk is
never read (`test_write_statistics_not_arrow` in `tests/geospatial.rs`
caught this in CI).

They pass on `main` as well, so they pin the behaviour to `main`'s. The
second test fails if the `k >= vals_in_chunk` check is removed. The
existing writer and page-size tests also pass.

Benchmarks: `arrow_writer`, `/default` props, on a quiet GCE
c3-standard-8. Each variant ran twice, interleaved, and the numbers
below are the two runs:

| case | main | this PR |
| --- | --- | --- |
| byte_array_sparse_99pct_null | 10.6 / 10.7 ms | 9.3 / 9.3 ms
(**−13%**) |
| string_and_binary_view | 52.9 / 52.6 ms | 51.7 / 51.5 ms |
| string | 150.9 / 152.9 ms | 149.6 / 149.5 ms |
| string_dictionary | 74.4 / 74.4 ms | 73.8 / 73.6 ms |
| string_ree_95pct_null | 31.3 / 31.2 ms | 31.1 / 30.9 ms |
| string_non_null | 176.4 / 179.7 ms | 175.7 / 176.0 ms |
| large_string_non_null | 58.1 / 58.0 ms | 58.1 / 57.9 ms |
| list_string_ree | 137.7 / 137.6 ms | 138.9 / 138.9 ms |

Every case except the sparse one is within noise. `perf` on
`byte_array_sparse_99pct_null`: `byte_budget_sub_batch` (with the
inlined def-level scan) drops from 10.2% to 0.6% of samples, and
`count_values_within_byte_budget_gather` rises from 0.9% to 1.6%.

# Are there any user-facing changes?

No.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Squash those bugs parquet parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parquet: clustered nulls can overflow dictionary pages despite byte-budget batching

4 participants