perf: vectorize spark_unscaled_value (9x faster)#4972
Open
u70b3 wants to merge 1 commit into
Open
Conversation
u70b3
force-pushed
the
perf/vectorize-unscaled-value
branch
from
July 18, 2026 02:47
40a7762 to
81ebfdf
Compare
Replace the per-element Int64Builder loop in the array branch with the vectorized Arrow unary kernel: the Decimal128 values buffer is mapped to Int64 in a single pass and the null buffer is carried over untouched (zero-copy). The scalar branch is unchanged. Benchmark (8192 rows, Decimal128(20,2), benches/unscaled_value.rs): - no nulls: 29.5 us -> 3.2 us (~9.3x) - sparse nulls (1 in 10): 35.5 us -> 3.0 us (~11.7x) - dense nulls (1 in 2): 30.5 us -> 2.9 us (~10.4x) Part of apache#4942
u70b3
force-pushed
the
perf/vectorize-unscaled-value
branch
from
July 18, 2026 04:39
81ebfdf to
675d3eb
Compare
andygrove
approved these changes
Jul 18, 2026
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?
Part of #4942.
Rationale for this change
spark_unscaled_valueis injected by Spark'sDecimalAggregatesrule for everysum/avgover narrow decimals, so it sits on the TPC-DS decimal aggregation hot path. The array branch used a per-elementInt64Builderloop.What changes are included in this PR?
unarykernel: the Decimal128 values buffer is mapped to Int64 in a single pass and the null buffer is carried over untouched (zero-copy). The scalar branch is unchanged.benches/unscaled_value.rs) covering no-null / sparse-null (1 in 10) / dense-null (1 in 2) shapes at 8192 rows, following the scalar expression optimization guide.Benchmark results (8192 rows, Decimal128(20,2), median):
How are these changes tested?
datafusion-comet-spark-exprsuite passes (497 tests), plusclippy --all-targets -D warningsandfmt.