Skip to content

fix(parquet): stop bypassing write_batch_size for compact level data - #12217

Closed
siddubakka wants to merge 1 commit into
apache:mainfrom
siddubakka:fix/10931-write-batch-size
Closed

siddubakka wants to merge 1 commit into
apache:mainfrom
siddubakka:fix/10931-write-batch-size

Conversation

@siddubakka

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

set_write_batch_size documents write_batch_size as the granularity at which limits such as set_data_page_row_count_limit are checked. Columns with compact level data did not follow that rule. Their mini-batch size was data_page_row_count_limit, so set_write_batch_size had no effect on a nullable column whose batch happened to contain no nulls.

The condition was on the level data rather than the schema, so the same column with the same writer properties produced different page boundaries depending on whether a batch contained a null. Page boundaries should follow the properties that were set, not the contents of the batch.

What changes are included in this PR?

write_batch_internal now always batches at write_batch_size. The special case for compact level data added in #9831 and the two condition variables behind it are removed, and a short comment explains why the batch size is what it is.

The plan comment on the issue proposed taking the smaller of write_batch_size and data_page_row_count_limit. I built that version first. It still leaves the compact path different from the other two when write_batch_size is larger than the row count limit, which is the write_batch_size = 100000 case in the issue's reproduction. Batching at write_batch_size directly matches the documentation and makes all three level shapes produce identical page boundaries at every write_batch_size in the reproduction.

Are these changes tested?

Added test_write_batch_size_bounds_compact_level_batches in parquet/tests/arrow_writer/layout.rs. It repeats the issue's reproduction: 12000 Int64 rows, row count limit 3000, dictionary disabled, for absent, uniform and materialized level data at write_batch_size 8, 64, 1024 and 100000. It asserts the page row counts from the issue's table and that the three shapes agree.

I also ran cargo bench -p parquet --bench arrow_writer before and after the change for the groups that take this path. This machine cannot compare runs that are separated by a rebuild. Repeating the same commit in a later session moved those benches by 20 to 40 percent, while two runs of the same binary back to back stayed within about 6 percent, so I am not quoting a number for this change because it would not be honest.

What does change is the batch size itself. At default settings the compact path used to write 20000 rows per mini-batch, which is the data page row count limit, and it now writes write_batch_size rows, which is 1024 by default. The larger batch was an optimization from #9831. This PR gives it back in exchange for the behavior the documentation describes. I can run a cleaner comparison if reviewers want numbers.

Are there any significant user-facing changes?

Page layout changes for columns with compact level data. With the same writer properties, pages now end at write_batch_size boundaries like every other column instead of at data_page_row_count_limit boundaries, so files written before and after this change can have different page boundaries for such columns. There are no API changes.

AI usage disclosure

I used an AI assistant to draft the code change, the test and this description. The parquet test suite and clippy were run locally before opening this PR.

write_batch_internal used data_page_row_count_limit as the mini-batch size when both level vectors were compact, so set_write_batch_size had no effect for columns with compact level data. Batch at write_batch_size unconditionally so page boundaries follow the documented granularity.
@boring-cyborg boring-cyborg Bot added the parquet parquet crate label Nov 12, 2026
@etseidl

etseidl commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

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/10931-write-batch-size (94c8dd6) to cd91f89 (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 completed (GKE) | trigger

Target: arrow_writer

Comparing fix/10931-write-batch-size (94c8dd6) to cd91f89 (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-ty64ekgq-c91a1467-2qwk

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

uname:

Linux bench-c6856719175-4932-zhkj6 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 1775.4s
Peak memory 2.1 GiB
Avg memory 196.4 MiB
CPU user 1740.4s
CPU sys 33.8s
Peak spill 0 B

branch

Metric Value
Wall time 1775.4s
Peak memory 2.0 GiB
Avg memory 193.5 MiB
CPU user 1736.9s
CPU sys 34.3s
Peak spill 0 B
arrow_writer — shard 2/4

Node: gk3-benchmark-cluster-nap-ty64ekgq-c91a1467-rbtp

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

uname:

Linux bench-c6856719175-4933-8bt2x 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 1880.4s
Peak memory 2.2 GiB
Avg memory 374.5 MiB
CPU user 1825.4s
CPU sys 52.8s
Peak spill 0 B

branch

Metric Value
Wall time 1900.4s
Peak memory 2.2 GiB
Avg memory 387.2 MiB
CPU user 1832.1s
CPU sys 63.1s
Peak spill 0 B
arrow_writer — shard 3/4

Node: gk3-benchmark-cluster-nap-ty64ekgq-c91a1467-4flt

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

uname:

Linux bench-c6856719175-4934-xw4hg 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 2085.5s
Peak memory 2.2 GiB
Avg memory 347.0 MiB
CPU user 2021.3s
CPU sys 60.3s
Peak spill 0 B

branch

Metric Value
Wall time 2090.5s
Peak memory 2.2 GiB
Avg memory 349.6 MiB
CPU user 2028.8s
CPU sys 58.8s
Peak spill 0 B
arrow_writer — shard 4/4

Node: gk3-benchmark-cluster-nap-ty64ekgq-c91a1467-x6qs

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

uname:

Linux bench-c6856719175-4935-65rjl 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 1830.4s
Peak memory 2.1 GiB
Avg memory 253.0 MiB
CPU user 1792.3s
CPU sys 33.8s
Peak spill 0 B

branch

Metric Value
Wall time 1840.4s
Peak memory 2.0 GiB
Avg memory 251.1 MiB
CPU user 1801.1s
CPU sys 33.0s
Peak spill 0 B

File an issue against this benchmark runner

@etseidl

etseidl commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

As I feared, this PR removes a useful optimization. I don't think matching overflow behavior justifies that loss.

I think we should add a section to the WriterProperties documentation explaining how write batch size interacts with page and dictionary size limits, and how none are guarantees, but best effort. We can then link to that section from the various setters.

@Rich-T-kid Rich-T-kid added the bug Squash those bugs label Nov 16, 2026
@siddubakka

Copy link
Copy Markdown
Contributor Author

@etseidl Thanks for running these, the numbers are useful.

You are right that this removes a real optimization. The regressions sit where I would expect them: primitive_all_null and struct_all_null default cases are up about 68 percent, fsb about 19, and the map, struct_non_null and string_non_null ndv cases in the 8 to 16 range. The suite total is roughly flat across the four shards though, and a few of the ndv high cardinality cases got faster, so the cost looks concentrated rather than broad. Either way it is a real cost.

One clarification, not a counterargument: the compact level representation from #9831 stays, only the batch granularity in write_batch_internal changes.

On the tradeoff, I think your read is the right one. The page row count limit is already best effort on the other two paths since pages fill to the next write_batch_size boundary, so matching that overflow behavior for compact data costs the optimization without buying a real guarantee. I am happy to write the docs section you described instead: a WriterProperties section covering how write_batch_size, data_page_row_count_limit and dictionary page size interact, with best effort wording, linked from the setters.

@adriangb said earlier that fixing the implementation was better than documenting it. If you two still prefer the code fix I will keep this PR as is. Otherwise I will close it and open the docs PR against the issue. Which way would you like it?

@adriangb

Copy link
Copy Markdown
Contributor

Lets go with the docs PR for now since there are tradeoffs in the implementation

@siddubakka

Copy link
Copy Markdown
Contributor Author

@adriangb Sounds good, closing this and opening the docs PR against #10931 instead.

@siddubakka siddubakka closed this Nov 18, 2026
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: write_batch_size is bypassed for columns with compact level data, contrary to its documentation

5 participants