perf: improve calculating length performance for nested arrays in row conversion#9079
Conversation
|
run benchmark row_format |
|
🤖 |
|
🤖: Benchmark completed Details
|
…culating-rows-length
|
run benchmark row_format |
|
🤖 |
|
🤖: Benchmark completed Details
|
…ow conversion (#9080) # Which issue does this PR close? N/A # Rationale for this change Making the row length calculation faster which result in faster row conversion # What changes are included in this PR? 1. Instead of iterating over the bytes and getting the length from the byte slice, we use the offsets directly, this is faster as it saves us going to the buffer 2. Added new API for `GenericByteViewArray` (explained below) # Are these changes tested? Yes # Are there any user-facing changes? Yes, added `lengths` function to `GenericByteViewArray` to get an iterator over the lengths of the items in the array ----- Related to: - #9078 - #9079 --------- Co-authored-by: Andrew Lamb <[email protected]>
…culating-rows-length # Conflicts: # arrow-row/src/lib.rs
|
@alamb can you please review and hopefully merge if approved with no comments |
alamb
left a comment
There was a problem hiding this comment.
Thank you for this PR @rluvaton
I have some concerns about the introduction of unsafe APIs and it wasn't clear how this would improve performance (and it doesn't seem like the benchmarks show any improvements)
Did you see improvements in any of your internal benchmarks?
arrow-row/src/lib.rs
Outdated
| } | ||
| } | ||
|
|
||
| /// Returns the length of the row at index `row` in bytes |
There was a problem hiding this comment.
Can you please document that "length" means bytes here (not, for example, columns)
arrow-row/src/lib.rs
Outdated
| /// | ||
| /// # Safety | ||
| /// Caller must ensure that `index` is less than the number of offsets (#rows + 1) | ||
| pub unsafe fn row_len_unchecked(&self, index: usize) -> usize { |
There was a problem hiding this comment.
Why do we need this new pub unsafe API?
in terms of pub it doesn't seem to be used anywhere other than row_len so we could at least make it non pul
In terms of unsafe, Given that row_len does an assert, what is the rationale for using unsafe rather than just normal array access?
As in, why not
pub fn row_len(&self, row: usize) -> usize {
self.offsets[row+1] - self.offsets[row]
}That would be simpler and not use unsafe
It in theory may have one extra bounds check, but unless the performance gains are compelling I think we should avoid adding new unsafe when possible
There was a problem hiding this comment.
removed the unchecked version and only kept row_len
Although the benchmarks show no improvement, there is no really a benchmark that go through that path extensively. This should improve the performance nonetheless as we are now doing less computation than before. |
|
show benchmark queue |
…n row conversion (#9078) # Which issue does this PR close? N/A # Rationale for this change Making the row length calculation faster which result in faster row conversion # What changes are included in this PR? Instead of iterating over the items in the array and getting the length from the byte slice, we use the offsets directly and zip with nulls if necessary # Are these changes tested? Existing tests # Are there any user-facing changes? Faster encoding ------ Split to 2 more PRs as the other 2 add a change to the public API Related to: - #9079 - #9080 --------- Co-authored-by: Andrew Lamb <[email protected]>
I see, perhaps we can add a benchmark case? |
BTW the benchmark runner was rebooted for some reason. I have fixed it |
…ow conversion (apache#9080) # Which issue does this PR close? N/A # Rationale for this change Making the row length calculation faster which result in faster row conversion # What changes are included in this PR? 1. Instead of iterating over the bytes and getting the length from the byte slice, we use the offsets directly, this is faster as it saves us going to the buffer 2. Added new API for `GenericByteViewArray` (explained below) # Are these changes tested? Yes # Are there any user-facing changes? Yes, added `lengths` function to `GenericByteViewArray` to get an iterator over the lengths of the items in the array ----- Related to: - apache#9078 - apache#9079 --------- Co-authored-by: Andrew Lamb <[email protected]>
…n row conversion (apache#9078) # Which issue does this PR close? N/A # Rationale for this change Making the row length calculation faster which result in faster row conversion # What changes are included in this PR? Instead of iterating over the items in the array and getting the length from the byte slice, we use the offsets directly and zip with nulls if necessary # Are these changes tested? Existing tests # Are there any user-facing changes? Faster encoding ------ Split to 2 more PRs as the other 2 add a change to the public API Related to: - apache#9079 - apache#9080 --------- Co-authored-by: Andrew Lamb <[email protected]>
… conversion (apache#9079) # Which issue does this PR close? N/A # Rationale for this change Making the row length calculation faster which result in faster row conversion # What changes are included in this PR? 1. Instead of iterating over the rows and getting the length from the byte slice, we use the offsets directly, this 2. Added 3 new APIs for `Rows` (explained below) # Are these changes tested? Yes # Are there any user-facing changes? Yes, added 3 functions to `Rows`: - `row_len` - get the row length at index - `row_len_unchecked` - get the row length at index without bound checks - `lengths` - get iterator over the lengths of the rows ----- Related to: - apache#9078 - apache#9080 --------- Co-authored-by: Andrew Lamb <[email protected]>
Which issue does this PR close?
N/A
Rationale for this change
Making the row length calculation faster which result in faster row conversion
What changes are included in this PR?
Rows(explained below)Are these changes tested?
Yes
Are there any user-facing changes?
Yes, added 3 functions to
Rows:row_len- get the row length at indexrow_len_unchecked- get the row length at index without bound checkslengths- get iterator over the lengths of the rowsRelated to:
GenericByteArrayin row conversion #9078