Avoid redundant memory access in ArrowBytesViewMap for inline values#20807
Open
CuteChuanChuan wants to merge 2 commits intoapache:mainfrom
Open
Avoid redundant memory access in ArrowBytesViewMap for inline values#20807CuteChuanChuan wants to merge 2 commits intoapache:mainfrom
CuteChuanChuan wants to merge 2 commits intoapache:mainfrom
Conversation
9330fd7 to
dd4cc0b
Compare
Contributor
Author
|
Hi @Dandandan , |
Dandandan
reviewed
Mar 9, 2026
| // For non-inline strings (>12 bytes), fetch once from the array. | ||
| let view_bytes = view_u128.to_le_bytes(); | ||
| let input_value: &[u8] = if is_inline { | ||
| &view_bytes[4..4 + len as usize] |
Contributor
There was a problem hiding this comment.
I think we don'nt need this for the inline path (we use the u128 directly)
Dandandan
reviewed
Mar 9, 2026
| } else { | ||
| // to avoid redundant memory access during hash resolution and insertion. | ||
| // Inline strings (<= 12 bytes) use u128 directly. | ||
| let input_value: &[u8] = if !is_inline { |
Contributor
There was a problem hiding this comment.
Hmm can we just values.value(i).as_ref() to where it is used instead in the else branch ?
Dandandan
reviewed
Mar 9, 2026
| let (payload, new_view) = if is_inline { | ||
| // Extract inline bytes from view (only for new values) | ||
| let view_bytes = view_u128.to_le_bytes(); | ||
| let payload = make_payload_fn(Some(&view_bytes[4..4 + len as usize])); |
Contributor
There was a problem hiding this comment.
it looks like this param to the payload fn is not really used anymore, could we remove it?
The three actual implementations just ignore the param:
fn make_payload_fn(_value: Option<&[u8]>) {}
|_value| {
// assign new group index on each insert
let group_idx = self.num_groups;
self.num_groups += 1;
group_idx
},
|_value| {
// assign new group index on each insert
let group_idx = self.num_groups;
self.num_groups += 1;
group_idx
},
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?
Rationale for this change
ArrowBytesViewMap::insert_if_new_innercallsvalues.value(i)redundantly:findclosureFor inline strings (<=12 bytes),
values.value(i)is unnecessary since the data is embedded directly in the view.For non-inline strings (>12 bytes), it should only be called once.
What changes are included in this PR?
values.value(i). During insertion, push the originalview_u128directly.values.value(i)once before thefindclosure and reuse the result for both hash resolution and insertion.Are these changes tested?
Yes, covered by existing tests by running
cargo test -p datafusion-physical-expr-commonAre there any user-facing changes?
No. This is an internal performance optimization with no API changes.