Skip to content

feat/chore: introduce fallible alternatives for MutableBuffer - #10317

Merged
Jefffrey merged 14 commits into
apache:mainfrom
Rich-T-kid:rich-T-kid/fallible-mutable-buffer-api
Aug 4, 2026
Merged

Jefffrey merged 14 commits into
apache:mainfrom
Rich-T-kid:rich-T-kid/fallible-mutable-buffer-api

Conversation

@Rich-T-kid

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

see #9843.
MutableBuffer is a low-level building block used throughout the Arrow implementation. Every growth operation, reserve, resize, push, extend_from_slice, etc, can panic on arithmetic overflow or an invalid allocation layout. In library code that needs to surface errors gracefully. This PR adds methods to return errors instead of panicking.

I made new methods instead of adding conditional checks/wrappers for each method because its easier to slowly roll these changes out to call sites instead of swapping.

What changes are included in this PR?


┌──────────────────────────┬──────────────────────┐
│         Fallible         │      Infallible      │
├──────────────────────────┼──────────────────────┤
│ try_reserve              │ reserve              │
├──────────────────────────┼──────────────────────┤
│ try_repeat_slice_n_times │ repeat_slice_n_times │
├──────────────────────────┼──────────────────────┤
│ try_reallocate (private) │ reallocate           │
├──────────────────────────┼──────────────────────┤
│ try_resize               │ resize               │
├──────────────────────────┼──────────────────────┤
│ try_shrink_to_fit        │ shrink_to_fit        │
├──────────────────────────┼──────────────────────┤
│ try_extend_from_slice    │ extend_from_slice    │
├──────────────────────────┼──────────────────────┤
│ try_push                 │ push                 │
├──────────────────────────┼──────────────────────┤
│ try_extend_zeros         │ extend_zeros         │
└──────────────────────────┴──────────────────────┘

Are these changes tested?

Currently these methods aren't wired up to anything in the code base so I didn't include any test. Id be happy to include some. The implementations of the fallible API's are 1-1 to their non-fallible counter parts so i'm not sure if this would be needed.

Are there any user-facing changes?

yes, users can now work with errors instead of having their programs panic.

@github-actions github-actions Bot added the arrow Changes to the arrow crate label Jul 10, 2026
@Rich-T-kid

Rich-T-kid commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor Author

I made new methods instead of adding conditional checks/wrappers for each method because its easier to slowly roll these changes out to call sites instead of swapping.

once this is merged Ill work on updating call sites. From my understanding this isn't always a 1-1 switch, its only possible to use the fallible alternative if the calling functions also returns an error

@cetra3

cetra3 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

I just saw your PR when I raised my own one: #10329! Sorry for the double up of work...

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

I just saw your PR when I raised my own one: #10329! Sorry for the double up of work...

@cetra3 No worries — to avoid having the maintainers review two separate PRs, would you mind closing #10329 and reviewing this one instead? That way we can consolidate our approaches and make it easier to review. We can also split off the follow-up work of propagating the fallible version of the API throughout the arrow codebase. Let me know if this makes sense!

@cetra3

cetra3 commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Hey no worries I will close it off.

I do like the following differences from this PR (if you could fold them in to this one):

  • It doesn't duplicate the logic, i.e, the fallible versions are just try_<method>().unwrap() which means we don't need to adjust it in two places
  • It uses an opaque struct rather than an enum, which means we are more free to adjust implementation without changing internals, making it a breaking api change.

@Jefffrey Jefffrey 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.

It doesn't duplicate the logic, i.e, the fallible versions are just try_().unwrap() which means we don't need to adjust it in two places

this would be pretty neat to have if possible

Comment thread arrow-buffer/src/buffer/mutable.rs Resolved
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

It doesn't duplicate the logic, i.e, the fallible versions are just try_().unwrap() which means we don't need to adjust it in two places

This makes sense, this is a much cleaner pattern and it makes migration later down the line.

It uses an opaque struct rather than an enum, which means we are more free to adjust implementation without changing internals, making it a breaking api change.

I can see how this may be a worry but I think the number of ways these functions can fail is very small. I think an enum is more applicable in this case. happy to hear other thoughts on this.

@Rich-T-kid
Rich-T-kid force-pushed the rich-T-kid/fallible-mutable-buffer-api branch 2 times, most recently from 349c425 to 56c9f81 Compare July 14, 2026 15:17
@Rich-T-kid
Rich-T-kid force-pushed the rich-T-kid/fallible-mutable-buffer-api branch from 56c9f81 to ad30053 Compare July 14, 2026 15:19
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

@cetra3 could you take another look?

Comment thread arrow-buffer/src/buffer/mutable.rs Outdated
Ok(())
}
#[cold]
#[allow(dead_code)]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

setting this to #[expect(dead_code)] work fine for local development but it cause this ci to fail.

Comment thread arrow-buffer/src/buffer/mutable.rs Outdated
@@ -140,13 +174,13 @@ impl MutableBuffer {
NonNull::new(raw_ptr).unwrap_or_else(|| handle_alloc_error(layout))

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.

This is still a panic on allocation failure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch. The one way this could fail is if we OOM.

We could do something like this

Suggested change
NonNull::new(raw_ptr).unwrap_or_else(|| handle_alloc_error(layout))
let raw_ptr = unsafe { std::alloc::alloc(layout) };
if raw_ptr.is_null() {
return Err(MutableBufferError::OOM);
}
NonNull::new(raw_ptr).unwrap_or_else(|| handle_alloc_error(layout))

But I think handle_alloc_error already deals with this. I think running out of memory is a condition where the program should panic.

We could bubble up the error to the caller but there aren't many things you can do when your process runs out of memory, I'm sure it would be similar handling to what handle_alloc_error already does. I don't have too strong of an opinion either way, happy to try either approach.

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 use a memory limited global allocator in some scenarios already, and if we want to move to custom allocators, we don't want to capture the panic here.

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.e, in my PR I had a simple match statement:

                match NonNull::new(raw_ptr) {
                    Some(data) => data,
                    None => return Err(TryReserveError::new(layout.size())),
                }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

make sense, 2d0f74fe takes a similar approach.

I use a memory limited global allocator in some scenarios already

Im curious as to why? is this mostly for testing in low memory enviroments?

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.

My interest in this PR is to help with: apache/datafusion#22758

The linux allocator famously does not limit allocations, and so you can get reaped by the OOM killer easily.

If we have a global allocator that internally limits how many allocations it dishes out, we can course correct in code if an error is returned. A panic still works, but this is a panic which is a pretty blunt instrument and means we can't take corrective action in code easily, which is what I found in testing.

I.e, if we have a memory limited allocator we can use this as a gauge to whether we need to spill memory to disk etc... so it's very useful as a tool there

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nice, I also have interest in apache/datafusion#22758 & #8938

If we have a global allocator that internally limits how many allocations it dishes out, we can course correct in code if an error is returned

make sense.

Would the next step be to replace all OOM panics with error propagation? Off the top of my head, I think arrow-buffer's crate deals with memory management most directly out of all the crates, so it would be a good place to start.

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.

are there any downstream concerns with replacing what we previously did (calling handle_alloc_error()) with just an error and relying on downstream to properly handle (in this case theyd just do a regular panic now)

@Rich-T-kid
Rich-T-kid requested a review from Jefffrey July 15, 2026 02:37
@Rich-T-kid
Rich-T-kid force-pushed the rich-T-kid/fallible-mutable-buffer-api branch from 2d0f74e to 0b1a641 Compare July 15, 2026 03:09

@Jefffrey Jefffrey 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.

it would be good to preserve some of the useful comments as it looks like theyre getting lost in the port

and i wonder if we'll need to run benches for these changes (if i can find appropriate ones)

Comment thread arrow-buffer/src/buffer/mutable.rs Resolved
Comment thread arrow-buffer/src/buffer/mutable.rs Resolved
Comment thread arrow-buffer/src/buffer/mutable.rs Resolved
Comment thread arrow-buffer/src/buffer/mutable.rs Outdated
@@ -140,13 +174,13 @@ impl MutableBuffer {
NonNull::new(raw_ptr).unwrap_or_else(|| handle_alloc_error(layout))

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.

are there any downstream concerns with replacing what we previously did (calling handle_alloc_error()) with just an error and relying on downstream to properly handle (in this case theyd just do a regular panic now)

@Rich-T-kid

Rich-T-kid commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor Author

it would be good to preserve some of the useful comments as it looks like theyre getting lost in the port

6f03bec re-introduces the comments

are there any downstream concerns with replacing what we previously did (calling handle_alloc_error()) with just an error and relying on downstream to properly handle

im not sure. I think the best person to ask would be @alamb.

from the docs for handle_alloc_error

it may either panic (resulting in unwinding or aborting as per configuration for all panics), or abort the process (with no unwinding).

it seems that once this branch is hit there isn't much for the process to do anyway? in both cases it aborts the process.

@Jefffrey

Copy link
Copy Markdown
Contributor

run benchmarks mutable_buffer_repeat_slice buffer_create builder

@Jefffrey

Copy link
Copy Markdown
Contributor

from the docs for handle_alloc_error

it may either panic (resulting in unwinding or aborting as per configuration for all panics), or abort the process (with no unwinding).

it seems that once this branch is hit there isn't much for the process to do anyway? in both cases it aborts the process.

yeah I was mainly looking at this part of its doc:

Callers of memory allocation APIs wishing to cease execution in response to an allocation error are encouraged to call this function, rather than directly invoking panic! or similar.

but its probably fine i guess?

@adriangbot

This comment was marked as duplicate.

@adriangbot

This comment was marked as duplicate.

@adriangbot

This comment was marked as duplicate.

@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark completed (GKE) | trigger

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

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
Details

group                                          main                                    rich-T-kid_fallible-mutable-buffer-api
-----                                          ----                                    --------------------------------------
bench_bool/bench_bool                          1.24    362.6±1.56µs  1379.1 MB/sec     1.00    293.1±0.32µs  1706.1 MB/sec
bench_decimal128_builder                       1.00    200.8±7.41µs        ? ?/sec     1.00    200.9±6.56µs        ? ?/sec
bench_decimal256_builder                       1.00    201.3±7.51µs        ? ?/sec     1.00    202.1±6.89µs        ? ?/sec
bench_decimal32_builder                        1.00     81.4±2.28µs        ? ?/sec     1.00     81.4±2.59µs        ? ?/sec
bench_decimal64_builder                        1.00     99.9±4.61µs        ? ?/sec     1.00    100.2±4.93µs        ? ?/sec
bench_primitive/bench_primitive                1.00     48.5±0.26µs    80.6 GB/sec     1.00     48.5±0.18µs    80.5 GB/sec
bench_primitive/bench_string                   1.02      5.4±0.02ms  1207.9 MB/sec     1.00      5.3±0.02ms  1230.0 MB/sec
bench_primitive_nulls/bench_primitive_nulls    1.00  1205.3±140.54µs        ? ?/sec    1.00  1200.9±145.49µs        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 85.0s
Peak memory 18.1 MiB
Avg memory 8.6 MiB
CPU user 73.1s
CPU sys 6.8s
Peak spill 0 B

branch

Metric Value
Wall time 85.0s
Peak memory 15.9 MiB
Avg memory 8.6 MiB
CPU user 71.8s
CPU sys 6.3s
Peak spill 0 B

File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark completed (GKE) | trigger

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

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
Details

group                             main                                   rich-T-kid_fallible-mutable-buffer-api
-----                             ----                                   --------------------------------------
Buffer::from_iter bool            1.00      3.1±0.01ms        ? ?/sec    1.00      3.1±0.04ms        ? ?/sec
MutableBuffer iter bitset         1.00     46.7±1.80ms        ? ?/sec    1.00     46.6±0.55ms        ? ?/sec
MutableBuffer::from_iter bool     1.00      3.1±0.01ms        ? ?/sec    1.37      4.2±0.03ms        ? ?/sec
from_slice                        1.00    222.4±0.95µs        ? ?/sec    1.15    255.2±0.70µs        ? ?/sec
from_slice prepared               1.01    213.6±0.59µs        ? ?/sec    1.00    211.5±0.57µs        ? ?/sec
mutable                           1.01    279.5±0.61µs        ? ?/sec    1.00    275.5±0.84µs        ? ?/sec
mutable extend                    1.00    541.9±0.96µs        ? ?/sec    1.01    549.6±0.85µs        ? ?/sec
mutable iter extend_from_slice    1.01   1154.6±1.54µs        ? ?/sec    1.00  1139.6±13.16µs        ? ?/sec
mutable prepared                  1.02    185.6±0.57µs        ? ?/sec    1.00    182.5±0.81µs        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 95.0s
Peak memory 141.2 MiB
Avg memory 25.6 MiB
CPU user 77.9s
CPU sys 13.0s
Peak spill 0 B

branch

Metric Value
Wall time 100.0s
Peak memory 141.3 MiB
Avg memory 25.4 MiB
CPU user 80.0s
CPU sys 14.1s
Peak spill 0 B

File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark completed (GKE) | trigger

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

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
Details

group                                                                     main                                   rich-T-kid_fallible-mutable-buffer-api
-----                                                                     ----                                   --------------------------------------
MutableBuffer repeat slice/extend_from_slice loop/slice_len=100 n=1024    1.00      3.2±0.04µs        ? ?/sec    1.00      3.2±0.04µs        ? ?/sec
MutableBuffer repeat slice/extend_from_slice loop/slice_len=100 n=3       1.00     93.5±0.49ns        ? ?/sec    1.04     97.3±0.45ns        ? ?/sec
MutableBuffer repeat slice/extend_from_slice loop/slice_len=100 n=64      1.00    313.2±1.78ns        ? ?/sec    1.05    330.1±2.20ns        ? ?/sec
MutableBuffer repeat slice/extend_from_slice loop/slice_len=100 n=8192    1.00     25.0±0.24µs        ? ?/sec    1.02     25.4±0.18µs        ? ?/sec
MutableBuffer repeat slice/extend_from_slice loop/slice_len=20 n=1024     1.00      2.4±0.05µs        ? ?/sec    1.00      2.4±0.01µs        ? ?/sec
MutableBuffer repeat slice/extend_from_slice loop/slice_len=20 n=3        1.12     78.4±0.28ns        ? ?/sec    1.00     70.3±0.48ns        ? ?/sec
MutableBuffer repeat slice/extend_from_slice loop/slice_len=20 n=64       1.01    263.6±1.94ns        ? ?/sec    1.00    259.9±0.78ns        ? ?/sec
MutableBuffer repeat slice/extend_from_slice loop/slice_len=20 n=8192     1.00     17.9±0.76µs        ? ?/sec    1.03     18.3±0.04µs        ? ?/sec
MutableBuffer repeat slice/extend_from_slice loop/slice_len=3 n=1024      1.00      2.4±0.00µs        ? ?/sec    1.00      2.4±0.00µs        ? ?/sec
MutableBuffer repeat slice/extend_from_slice loop/slice_len=3 n=3         1.03     72.4±0.26ns        ? ?/sec    1.00     70.4±0.24ns        ? ?/sec
MutableBuffer repeat slice/extend_from_slice loop/slice_len=3 n=64        1.00    206.1±1.15ns        ? ?/sec    1.10    225.8±0.22ns        ? ?/sec
MutableBuffer repeat slice/extend_from_slice loop/slice_len=3 n=8192      1.00     17.2±1.01µs        ? ?/sec    1.05     18.1±0.03µs        ? ?/sec
MutableBuffer repeat slice/repeat_slice_n_times/slice_len=100 n=1024      1.01   1260.8±1.21ns        ? ?/sec    1.00   1252.1±1.37ns        ? ?/sec
MutableBuffer repeat slice/repeat_slice_n_times/slice_len=100 n=3         1.23    108.5±1.30ns        ? ?/sec    1.00     88.2±0.61ns        ? ?/sec
MutableBuffer repeat slice/repeat_slice_n_times/slice_len=100 n=64        1.00    210.5±1.12ns        ? ?/sec    1.09    229.7±1.17ns        ? ?/sec
MutableBuffer repeat slice/repeat_slice_n_times/slice_len=100 n=8192      1.00     10.5±0.00µs        ? ?/sec    1.00     10.5±0.01µs        ? ?/sec
MutableBuffer repeat slice/repeat_slice_n_times/slice_len=20 n=1024       1.00    364.8±0.95ns        ? ?/sec    1.00    364.6±0.83ns        ? ?/sec
MutableBuffer repeat slice/repeat_slice_n_times/slice_len=20 n=3          1.08     81.7±0.56ns        ? ?/sec    1.00     75.5±1.10ns        ? ?/sec
MutableBuffer repeat slice/repeat_slice_n_times/slice_len=20 n=64         1.01    153.9±0.79ns        ? ?/sec    1.00    153.1±0.78ns        ? ?/sec
MutableBuffer repeat slice/repeat_slice_n_times/slice_len=20 n=8192       1.00      2.0±0.00µs        ? ?/sec    1.00      2.0±0.00µs        ? ?/sec
MutableBuffer repeat slice/repeat_slice_n_times/slice_len=3 n=1024        1.01    185.4±1.13ns        ? ?/sec    1.00    182.9±1.10ns        ? ?/sec
MutableBuffer repeat slice/repeat_slice_n_times/slice_len=3 n=3           1.00     80.6±0.91ns        ? ?/sec    1.01     81.6±1.03ns        ? ?/sec
MutableBuffer repeat slice/repeat_slice_n_times/slice_len=3 n=64          1.02    106.3±1.46ns        ? ?/sec    1.00    104.0±0.37ns        ? ?/sec
MutableBuffer repeat slice/repeat_slice_n_times/slice_len=3 n=8192        1.03    417.8±1.13ns        ? ?/sec    1.00    404.6±1.50ns        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 235.1s
Peak memory 9.7 MiB
Avg memory 5.2 MiB
CPU user 228.1s
CPU sys 0.0s
Peak spill 0 B

branch

Metric Value
Wall time 235.1s
Peak memory 8.6 MiB
Avg memory 4.1 MiB
CPU user 230.2s
CPU sys 0.0s
Peak spill 0 B

File an issue against this benchmark runner

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

It uses an opaque struct rather than an enum, which means we are more free to adjust implementation without changing internals, making it a breaking api change.

it just came to mind that we can mark this enum as #[non_exhaustive]

the error set is probably bounded enough to not require this i think? i.e. how many more error types would be possible in this context, to warrant this for the future

this is also true, no other error cases come to mind right now. ill revert the #[non_exhaustive] unless anyone feels strongly

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

do we need to merge main into this to fix the CI issue?

@Jefffrey

Copy link
Copy Markdown
Contributor

just having a hard time determining if there are any performance regressions or its just noise in the benchmarks 🤔

@Rich-T-kid

Rich-T-kid commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor Author

just having a hard time determining if there are any performance regressions or its just noise in the benchmarks 🤔

nothing logically should have changed right? just a couple extra boolean checks for things like

 let total_bytes = repeat_count
            .checked_mul(bytes_per_copy)
            .ok_or(MutableBufferError::LengthOverflow)?;

it is weird how MutableBuffer::from_iter bool seem to regress over multiple benchmark calls

MutableBuffer::from_iter bool     1.00      3.1±0.01ms        ? ?/sec    1.36      4.2±0.04ms        ? ?/sec

&

MutableBuffer::from_iter bool     1.00      3.1±0.01ms        ? ?/sec    1.37      4.2±0.03ms        ? ?/sec

like @/alamb mentioned

We have found boolean benchmarks to be quite sensitive -- allocation, alignment, etc

but then again bench_bool/bench_bool seems to have also flipped

old

bench_bool/bench_bool                          1.00    296.1±0.40µs  1688.8 MB/sec     1.22    361.2±0.21µs  1384.3 MB/sec

new

bench_bool/bench_bool                          1.24    362.6±1.56µs  1379.1 MB/sec     1.00    293.1±0.32µs  1706.1 MB/sec

@Jefffrey Jefffrey added the enhancement New feature/addition label Jul 30, 2026

@Jefffrey Jefffrey 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.

i guess the only thing to remark on is we could technically match on the errors and if we hit AllocationError just call handle_alloc_error as we essentially did before; but not sure how important it is to maintain this behaviour 🤔

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

after this is merged ill make a PR to wire up call sites to use the new try_*() methods. Ideally we can propogate these errors up the call stack as https://docs.rs/arrow/latest/arrow/error/enum.ArrowError.html#variant.MemoryError

we could technically match on the errors and if we hit AllocationError just call handle_alloc_error as we essentially did before

im not opposed to this but is there any reason why we shouldnt just pass up OOM errors if possible instead of panicking?

@Jefffrey

Copy link
Copy Markdown
Contributor

ah i more meant inside the existing infallible methods, for example in with_capacity() we could customize it to do handle_alloc_error on AllocationError and such

@Jefffrey
Jefffrey merged commit d282f80 into apache:main Aug 4, 2026
32 checks passed
@Jefffrey

Jefffrey commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

thanks @Rich-T-kid, @cetra3 & @alamb

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

nice! thanks @Jefffrey Ill make a follow up PR to replace the infallible methods with these new try_*() methods

Jefffrey pushed a commit that referenced this pull request Aug 14, 2026
# Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax.
-->

- Closes #9843.
- works off of #10317


# Rationale for this change

it is better to return an error and let down stream users decide how to
proceed than to panic.
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->

# What changes are included in this PR?
updates all call sites in the project to use the fallible alternative to
`mutableBuffer` methods.
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->

# Are these changes tested?
n/a behavior hasn't changed
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?

If this PR claims a performance improvement, please include evidence
such as benchmark results.
-->

# Are there any user-facing changes?
no public methods we changed in this PR
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.

If there are any breaking changes to public APIs, please call them out.
-->
MassivePizza pushed a commit to massive-com/arrow-rs that referenced this pull request Aug 19, 2026
# Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax.
-->

- Closes apache#9843.
- works off of apache#10317


# Rationale for this change

it is better to return an error and let down stream users decide how to
proceed than to panic.
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->

# What changes are included in this PR?
updates all call sites in the project to use the fallible alternative to
`mutableBuffer` methods.
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->

# Are these changes tested?
n/a behavior hasn't changed
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?

If this PR claims a performance improvement, please include evidence
such as benchmark results.
-->

# Are there any user-facing changes?
no public methods we changed in this PR
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.

If there are any breaking changes to public APIs, please call them out.
-->
Jefffrey pushed a commit that referenced this pull request Sep 2, 2026
…ors (#10736)

# Which issue does this PR close?

* Part of #10553
* Follows the `MutableBufferError` precedent from
#10317

# Rationale for this change

`OffsetBuffer::<i32>::from_lengths` panics once the lengths add up to
more than 2 GiB. The other overflow panics in `arrow-buffer` are the
same story.

# What changes are included in this PR?

A small `OverflowError` and a `try_` variant for functions that panics
on overflow:

* `OffsetBuffer::{try_new_zeroed, try_from_lengths,
try_from_repeated_length}`
* `OffsetBufferBuilder::{try_push_length, try_finish,
try_finish_cloned}`
* `NullBuffer::try_expand`

The panicking versions delegate to the fallible ones and re-panic with
the error's `Display`, so their panic messages are unchanged.

`try_push_length` leaves the builder unchanged when it fails.

# Are these changes tested?

Yes, new tests for the error paths. The existing `should_panic` tests
are untouched and still pass, which is what pins the panic messages.

# Are there any user-facing changes?

New public API only, no breaking changes.

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Sep 18, 2026
…ors (apache#10736)

# Which issue does this PR close?

* Part of apache#10553
* Follows the `MutableBufferError` precedent from
apache#10317

# Rationale for this change

`OffsetBuffer::<i32>::from_lengths` panics once the lengths add up to
more than 2 GiB. The other overflow panics in `arrow-buffer` are the
same story.

# What changes are included in this PR?

A small `OverflowError` and a `try_` variant for functions that panics
on overflow:

* `OffsetBuffer::{try_new_zeroed, try_from_lengths,
try_from_repeated_length}`
* `OffsetBufferBuilder::{try_push_length, try_finish,
try_finish_cloned}`
* `NullBuffer::try_expand`

The panicking versions delegate to the fallible ones and re-panic with
the error's `Display`, so their panic messages are unchanged.

`try_push_length` leaves the builder unchanged when it fails.

# Are these changes tested?

Yes, new tests for the error paths. The existing `should_panic` tests
are untouched and still pass, which is what pins the panic messages.

# Are there any user-facing changes?

New public API only, no breaking changes.

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Sep 21, 2026
…ors (apache#10736)

# Which issue does this PR close?

* Part of apache#10553
* Follows the `MutableBufferError` precedent from
apache#10317

# Rationale for this change

`OffsetBuffer::<i32>::from_lengths` panics once the lengths add up to
more than 2 GiB. The other overflow panics in `arrow-buffer` are the
same story.

# What changes are included in this PR?

A small `OverflowError` and a `try_` variant for functions that panics
on overflow:

* `OffsetBuffer::{try_new_zeroed, try_from_lengths,
try_from_repeated_length}`
* `OffsetBufferBuilder::{try_push_length, try_finish,
try_finish_cloned}`
* `NullBuffer::try_expand`

The panicking versions delegate to the fallible ones and re-panic with
the error's `Display`, so their panic messages are unchanged.

`try_push_length` leaves the builder unchanged when it fails.

# Are these changes tested?

Yes, new tests for the error paths. The existing `should_panic` tests
are untouched and still pass, which is what pins the panic messages.

# Are there any user-facing changes?

New public API only, no breaking changes.

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Sep 25, 2026
…ors (apache#10736)

# Which issue does this PR close?

* Part of apache#10553
* Follows the `MutableBufferError` precedent from
apache#10317

# Rationale for this change

`OffsetBuffer::<i32>::from_lengths` panics once the lengths add up to
more than 2 GiB. The other overflow panics in `arrow-buffer` are the
same story.

# What changes are included in this PR?

A small `OverflowError` and a `try_` variant for functions that panics
on overflow:

* `OffsetBuffer::{try_new_zeroed, try_from_lengths,
try_from_repeated_length}`
* `OffsetBufferBuilder::{try_push_length, try_finish,
try_finish_cloned}`
* `NullBuffer::try_expand`

The panicking versions delegate to the fallible ones and re-panic with
the error's `Display`, so their panic messages are unchanged.

`try_push_length` leaves the builder unchanged when it fails.

# Are these changes tested?

Yes, new tests for the error paths. The existing `should_panic` tests
are untouched and still pass, which is what pins the panic messages.

# Are there any user-facing changes?

New public API only, no breaking changes.

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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 arrow-buffer enhancement New feature/addition

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants