This is an automated email from the ASF dual-hosted git repository.

dheres pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new c129c7cfc2 Avoid allocating a `Vec` in `StructBuilder` (#9428)
c129c7cfc2 is described below

commit c129c7cfc27bf64ea07665f27db5bc1f485b66cc
Author: Fokko Driesprong <[email protected]>
AuthorDate: Wed Feb 18 16:22:16 2026 +0100

    Avoid allocating a `Vec` in `StructBuilder` (#9428)
    
    # Which issue does this PR close?
    
    Resolves #9427
    
    While going through the code, @scovich noticed that it allocates a
    `vec![false; n]` to be appended to the null buffer, which is not very
    efficent:
    
    ```
    append_nulls: vec![false; n] (old) vs append_n_nulls (new)
    
    ┌─────────┬─────────────────┬──────────────────────┬─────────┐
    │    n    │ old (vec alloc) │ new (append_n_nulls) │ speedup │
    ├─────────┼─────────────────┼──────────────────────┼─────────┤
    │ 100     │ 82 ns           │ 43 ns                │ ~2x     │
    ├─────────┼─────────────────┼──────────────────────┼─────────┤
    │ 1,000   │ 319 ns          │ 47 ns                │ ~7x     │
    ├─────────┼─────────────────┼──────────────────────┼─────────┤
    │ 10,000  │ 2,540 ns        │ 68 ns                │ ~37x    │
    ├─────────┼─────────────────┼──────────────────────┼─────────┤
    │ 100,000 │ 25,526 ns       │ 293 ns               │ ~87x    │
    └─────────┴─────────────────┴──────────────────────┴─────────┘
    ```
    
    # Rationale for this change
    
    MOAR efficient
    
    # What changes are included in this PR?
    
    Avoid allocating a `Vec`.
    
    # Are these changes tested?
    
    Existing tests
    
    # Are there any user-facing changes?
    
    Less memory consumption and a happy CPU
---
 arrow-array/src/builder/struct_builder.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arrow-array/src/builder/struct_builder.rs 
b/arrow-array/src/builder/struct_builder.rs
index 4fb312739c..ad58e00857 100644
--- a/arrow-array/src/builder/struct_builder.rs
+++ b/arrow-array/src/builder/struct_builder.rs
@@ -222,7 +222,7 @@ impl StructBuilder {
     /// Appends `n` `null`s into the builder.
     #[inline]
     pub fn append_nulls(&mut self, n: usize) {
-        self.null_buffer_builder.append_slice(&vec![false; n]);
+        self.null_buffer_builder.append_n_nulls(n);
     }
 
     /// Builds the `StructArray` and reset this builder.

Reply via email to