perf(parquet): slice up contiguous buffer for decimals and fsb - #10364
Conversation
50edfd3 to
f62743e
Compare
This allows optimizations since iterators uphold invariants.
Revert this when MSRV is bumped to at least 1.93.
# Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. --> - Related to #10364 (review). # Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> # What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> # Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? If this PR claims a performance improvement, please include evidence such as benchmark results. --> # Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please call them out. -->
|
run benchmark arrow_writer |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
run benchmark arrow_writer |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing parquet-contiguous-decimal (0495502) to cd17899 (merge-base) diff File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
alamb
left a comment
There was a problem hiding this comment.
Thanks @MassivePizza and @Jefffrey -- this looks great to me
| let mut values = Vec::with_capacity(indices.len()); | ||
| for i in indices { | ||
| let mut value = array.value(i).to_le_bytes().to_vec(); | ||
| let mut suffix = vec![0; 8]; |
There was a problem hiding this comment.
that is indeed an expensive way to append 8 bytes
| }) | ||
| } | ||
|
|
||
| trait NativeDecimalType: DecimalType { |
There was a problem hiding this comment.
Maybe we could just add these to the DecimalType trait itself (rather than a private trait) -- perhaps as a follow on PR
I suspect this would perform well |
|
Thanks @MassivePizza and @Jefffrey |
Which issue does this PR close?
N/A
Rationale for this change
Converting decimals and FixedLenByteArrays to individual allocs requires a lot of alloc+drop time and memory overhead.
What changes are included in this PR?
Allocate one big buffer, and cut it up into slices of
bytes::Bytes. This amortizes the alloc upfront, and effectively eliminates the drop overhead by turning a dealloc to an Arc decrement per slice.This still has moderate memory overhead.
Bytesis 32 bytes, while the slices usually expose less than 16 bytes at a time e.g. UUIDs or decimal128, but a lot more effort would be required to implement a (perhaps borrowed?) alternative that behaves likeFixedLenByteArray.There are a few other ideas worth exploring, primarily custom
ColumnValueEncoders that converts on the fly to avoid the temporary allocs all together.There is also a small outlining+inlining inExtracted to #10389.compare_greaterto help out in theget_min_maxloop.Are these changes tested?
Should be covered by existing tests. There are also new benches included (extracted to #10388):
decimal bench
fsb bench
Are there any user-facing changes?
No.