Skip to content

perf(parquet): slice up contiguous buffer for decimals and fsb#10364

Open
MassivePizza wants to merge 6 commits into
apache:mainfrom
massive-com:parquet-contiguous-decimal
Open

perf(parquet): slice up contiguous buffer for decimals and fsb#10364
MassivePizza wants to merge 6 commits into
apache:mainfrom
massive-com:parquet-contiguous-decimal

Conversation

@MassivePizza

@MassivePizza MassivePizza commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

N/A

Rationale for this change

Converting decimals and FixedLenByteArrays to individual allocs requires a lot of alloc+drop time and memory overhead.

What changes are included in this PR?

Allocate one big buffer, and cut it up into slices of bytes::Bytes. This amortizes the alloc upfront, and effectively eliminates the drop overhead by turning a dealloc to an Arc decrement per slice.

This still has moderate memory overhead. Bytes is 32 bytes, while the slices usually expose less than 16 bytes at a time e.g. UUIDs or decimal128, but a lot more effort would be required to implement a (perhaps borrowed?) alternative that behaves like FixedLenByteArray.

There are a few other ideas worth exploring, primarily custom ColumnValueEncoders that converts on the fly to avoid the temporary allocs all together.

There is also a small outlining+inlining in compare_greater to help out in the get_min_max loop.

Are these changes tested?

Should be covered by existing tests. There are also new benches included:

decimal bench
Benchmarking decimal/default: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 5.4s, or reduce sample count to 90.
decimal/default         time:   [53.676 ms 53.979 ms 54.306 ms]
                        thrpt:  [1.0790 GiB/s 1.0855 GiB/s 1.0916 GiB/s]
                 change:
                        time:   [−44.611% −44.247% −43.885%] (p = 0.00 < 0.05)
                        thrpt:  [+78.204% +79.362% +80.542%]
                        Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
  4 (4.00%) high mild
  1 (1.00%) high severe
Benchmarking decimal/bloom_filter: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.8s, or reduce sample count to 70.
decimal/bloom_filter    time:   [66.597 ms 66.838 ms 67.095 ms]
                        thrpt:  [894.26 MiB/s 897.70 MiB/s 900.94 MiB/s]
                 change:
                        time:   [−40.229% −39.907% −39.555%] (p = 0.00 < 0.05)
                        thrpt:  [+65.440% +66.408% +67.306%]
                        Performance has improved.
Found 10 outliers among 100 measurements (10.00%)
  8 (8.00%) high mild
  2 (2.00%) high severe
Benchmarking decimal/parquet_2: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 10.8s, or reduce sample count to 40.
decimal/parquet_2       time:   [105.82 ms 106.23 ms 106.66 ms]
                        thrpt:  [562.52 MiB/s 564.84 MiB/s 567.02 MiB/s]
                 change:
                        time:   [−48.804% −48.523% −48.229%] (p = 0.00 < 0.05)
                        thrpt:  [+93.160% +94.263% +95.329%]
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe
Benchmarking decimal/zstd: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.4s, or reduce sample count to 70.
decimal/zstd            time:   [61.806 ms 62.013 ms 62.282 ms]
                        thrpt:  [963.36 MiB/s 967.55 MiB/s 970.78 MiB/s]
                 change:
                        time:   [−60.257% −59.907% −59.556%] (p = 0.00 < 0.05)
                        thrpt:  [+147.25% +149.42% +151.62%]
                        Performance has improved.
Found 11 outliers among 100 measurements (11.00%)
  1 (1.00%) low severe
  2 (2.00%) low mild
  5 (5.00%) high mild
  3 (3.00%) high severe
Benchmarking decimal/zstd_parquet_2: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 11.9s, or reduce sample count to 40.
decimal/zstd_parquet_2  time:   [119.51 ms 119.87 ms 120.29 ms]
                        thrpt:  [498.82 MiB/s 500.54 MiB/s 502.07 MiB/s]
                 change:
                        time:   [−55.716% −55.352% −54.992%] (p = 0.00 < 0.05)
                        thrpt:  [+122.18% +123.98% +125.82%]
                        Performance has improved.
Found 11 outliers among 100 measurements (11.00%)
  2 (2.00%) low mild
  2 (2.00%) high mild
  7 (7.00%) high severe
Benchmarking decimal/cdc: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.8s, or reduce sample count to 60.
decimal/cdc             time:   [77.810 ms 78.092 ms 78.389 ms]
                        thrpt:  [765.42 MiB/s 768.33 MiB/s 771.11 MiB/s]
                 change:
                        time:   [−35.689% −35.360% −35.011%] (p = 0.00 < 0.05)
                        thrpt:  [+53.873% +54.703% +55.494%]
                        Performance has improved.
Found 10 outliers among 100 measurements (10.00%)
  10 (10.00%) high mild
fsb bench
fsb/default             time:   [5.4152 ms 5.4276 ms 5.4407 ms]
                        thrpt:  [2.8943 GiB/s 2.9013 GiB/s 2.9079 GiB/s]
                 change:
                        time:   [−27.824% −27.512% −27.215%] (p = 0.00 < 0.05)
                        thrpt:  [+37.391% +37.953% +38.550%]
                        Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
  1 (1.00%) low mild
  5 (5.00%) high mild
  1 (1.00%) high severe
fsb/bloom_filter        time:   [5.8681 ms 5.8908 ms 5.9154 ms]
                        thrpt:  [2.6621 GiB/s 2.6732 GiB/s 2.6835 GiB/s]
                 change:
                        time:   [−25.701% −25.298% −24.896%] (p = 0.00 < 0.05)
                        thrpt:  [+33.148% +33.866% +34.592%]
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) high mild
  3 (3.00%) high severe
fsb/parquet_2           time:   [8.6936 ms 8.7692 ms 8.8503 ms]
                        thrpt:  [1.7793 GiB/s 1.7957 GiB/s 1.8113 GiB/s]
                 change:
                        time:   [−31.621% −31.005% −30.286%] (p = 0.00 < 0.05)
                        thrpt:  [+43.444% +44.939% +46.243%]
                        Performance has improved.
Found 10 outliers among 100 measurements (10.00%)
  9 (9.00%) high mild
  1 (1.00%) high severe
fsb/zstd                time:   [7.1760 ms 7.2043 ms 7.2360 ms]
                        thrpt:  [2.1762 GiB/s 2.1858 GiB/s 2.1944 GiB/s]
                 change:
                        time:   [−21.480% −21.068% −20.631%] (p = 0.00 < 0.05)
                        thrpt:  [+25.994% +26.692% +27.356%]
                        Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) high mild
  1 (1.00%) high severe
fsb/zstd_parquet_2      time:   [9.2977 ms 9.4085 ms 9.5422 ms]
                        thrpt:  [1.6503 GiB/s 1.6737 GiB/s 1.6937 GiB/s]
                 change:
                        time:   [−30.266% −29.333% −28.383%] (p = 0.00 < 0.05)
                        thrpt:  [+39.632% +41.508% +43.401%]
                        Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
  4 (4.00%) high mild
  3 (3.00%) high severe
fsb/cdc                 time:   [7.9524 ms 7.9700 ms 7.9878 ms]
                        thrpt:  [1.9714 GiB/s 1.9758 GiB/s 1.9802 GiB/s]
                 change:
                        time:   [−21.280% −20.793% −20.375%] (p = 0.00 < 0.05)
                        thrpt:  [+25.589% +26.251% +27.033%]
                        Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high mildaa

Are there any user-facing changes?

No.

@github-actions github-actions Bot added parquet Changes to the parquet crate arrow Changes to the arrow crate labels Jul 17, 2026
3-6% improved arrow_writer "decimal" bench

#[inline(always)]
#[allow(clippy::eq_op)]
fn is_nan_with<T: ParquetValueType>(logical_type_ref: Option<&LogicalType>, val: &T) -> bool {

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.

I don't think the compare_greater/is_nan changes are really relevant to this PR, and will conflict with work already in progress to revamp NaN handling per changes to the spec (#9619). We can revisit once that merges.

)?)
}

fn create_decimal_bench_batch(size: usize, null_density: f32) -> Result<RecordBatch> {

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.

Could you break the benchmarks out into a separate PR? 🙏 It would be helpful.

Comment on lines +1840 to +1843
let mut out = [0; 12];
let value = array.value(i);
out[0..4].copy_from_slice(&value.to_le_bytes());
arena.extend_from_slice(&out);

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.

would it make a difference to change arena to vec![0; indices.len() * VALUE_SIZE] then use copy_from_slice into offsets to arena to avoid this intermediate out?

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

Labels

arrow Changes to the arrow crate parquet Changes to the parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants