Skip to content

Avoid allocating a Vec in StructBuilder#9428

Merged
Dandandan merged 1 commit intoapache:mainfrom
Fokko:fd-avoid-vec
Feb 18, 2026
Merged

Avoid allocating a Vec in StructBuilder#9428
Dandandan merged 1 commit intoapache:mainfrom
Fokko:fd-avoid-vec

Conversation

@Fokko
Copy link
Contributor

@Fokko Fokko commented Feb 18, 2026

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

Resolves apache#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    │
└─────────┴─────────────────┴──────────────────────┴─────────┘
```
@Dandandan Dandandan merged commit c129c7c into apache:main Feb 18, 2026
26 checks passed
@Dandandan
Copy link
Contributor

Thank you @Fokko ;)

@Fokko Fokko deleted the fd-avoid-vec branch February 18, 2026 20:02
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid allocating a Vec in StructBuilder

2 participants

Comments