perf: add repeat_slice_n_times to MutableBuffer#8658
Merged
alamb merged 6 commits intoapache:mainfrom Oct 21, 2025
Merged
Conversation
this will be used in: - apache#8653
This was referenced Oct 20, 2025
11 tasks
alamb
approved these changes
Oct 20, 2025
| } | ||
| } | ||
|
|
||
| /// Adding to this mutable buffer `slice_to_repeat` repeated `repeat_count` times. |
Contributor
There was a problem hiding this comment.
I am wondering how much the unsafe log copying here makes a difference, vs ensuring reserve is called correctly.
Did you measure with code that was like:
reserve(slice.len() * repeat_count);
for _ in 0..repeat_count {
buf.extend_from_slice(slice_to_repeat)
}|
|
||
| unsafe { | ||
| // Get to the start of the data before we started copying anything | ||
| let src = self.data.as_ptr().add(length_before) as *const u8; |
Contributor
There was a problem hiding this comment.
rustc can probably figure it out, but src is the same for all loop iterations so could be pulled out of the loop I think
Member
Author
There was a problem hiding this comment.
yeah, I thought about it but decided not to do it so the code for src and dst is close
Member
Author
|
Yes, I committed the benchmark I tested with
these are the results: Result |
Contributor
👍 |
alamb
pushed a commit
that referenced
this pull request
Oct 20, 2025
# Which issue does this PR close? N/A # Rationale for this change doing `OffsetBuffer::from_lengths(std::iter::repeat_n(size, value.len()));` does not utilize SIMD (I explain further if you want) See [GodBolt Link](https://godbolt.org/z/PTsfvfjqx) Extracted from: - #8653 After this and the pr below is merged will improve the datafusion scalar to array to use this and make it really really fast: - #8658 # What changes are included in this PR? added new function # Are these changes tested? yes # Are there any user-facing changes? yes
Member
Author
|
@alamb can you please merge |
Contributor
|
Done |
alamb
added a commit
that referenced
this pull request
Oct 28, 2025
Waiting for the PRs below to be merged first: - [x] #8654 - zip benchmarks **This PR include the following other PRs (unless merged)** to make the review easier, so please make sure to review them first - [x] #8658 - extracted from this - [x] #8656 - extracted from this # Which issue does this PR close? N/A # Rationale for this change Making zip really fast for scalars This is useful for `IF <expr> THEN <literal> ELSE <literal> END` # What changes are included in this PR? Created couple of implementation for zipping scalar, for primitive, bytes and fallback # Are these changes tested? existing tests # Are there any user-facing changes? new struct `ScalarZipper` TODO: - [x] Need to add comments if missing - [x] Add tests for decimal and timestamp to make sure the type is kept --------- Co-authored-by: Andrew Lamb <[email protected]>
mbrobbel
pushed a commit
that referenced
this pull request
Nov 3, 2025
**This PR include the following PRs changes** please make sure to review them first - [x] #8658 - [x] #8656 # Which issue does this PR close? N/A # Rationale for this change This will make scalar to array in DataFusion faster # What changes are included in this PR? Include the changes of: - #8658 - #8656 # Are these changes tested? yes # Are there any user-facing changes? yes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
N/A
Rationale for this change
I want to repeat the same value multiple times in a very fast way
which will be used in:
After this and the pr below is merged will improve the datafusion scalar to array to use this and make it really really fast:
What changes are included in this PR?
Created a function in
MutableBufferto repeat a slice a number of times in a logarithmic way to reduce memcopy callsAre these changes tested?
Yes
Are there any user-facing changes?
Yes, and added docs
Extracted from:
Benchmark results on local machine
these are the results:
Result