You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "neilconway (via GitHub)" <gi...@apache.org> on 2026/04/27 02:03:55 UTC
[PR] perf: Use bulk-NULL string builder in `initcap` [datafusion]
neilconway opened a new pull request, #21863:
URL: https://github.com/apache/datafusion/pull/21863
## Which issue does this PR close?
- Closes #21862.
## Rationale for this change
Similar to other recent changes, we can use the bulk-NULL string builders to avoid per-row NULL handling overhead.
Benchmarks:
- scalar/scalar_utf8: 227.4ns → 228.6ns (+0.53%)
- scalar/scalar_utf8view: 227.9ns → 229.2ns (+0.57%)
- size=1024 str_len=128/array_utf8: 276.5µs → 277.7µs (+0.43%)
- size=1024 str_len=128/array_utf8view: 223.3µs → 222.4µs (−0.40%)
- size=1024 str_len=16/array_utf8: 37.5µs → 37.4µs (−0.27%)
- size=1024 str_len=16/array_utf8view: 41.9µs → 39.3µs (−6.21%)
- size=4096 str_len=128/array_utf8: 1115.4µs → 1109.2µs (−0.56%)
- size=4096 str_len=128/array_utf8view: 900.2µs → 895.2µs (−0.56%)
- size=4096 str_len=16/array_utf8: 148.3µs → 148.4µs (+0.07%)
- size=4096 str_len=16/array_utf8view: 164.2µs → 153.8µs (−6.33%)
- size=8192 str_len=128/array_utf8: 2.2ms → 2.2ms (0.00%)
- size=8192 str_len=128/array_utf8view: 1811.2µs → 1819.2µs (+0.44%)
- size=8192 str_len=16/array_utf8: 299.0µs → 299.3µs (+0.10%)
- size=8192 str_len=16/array_utf8view: 330.6µs → 310.2µs (−6.17%)
- unicode size=1024/array_utf8: 772.2µs → 769.2µs (−0.39%)
- unicode size=1024/array_utf8view: 777.8µs → 779.2µs (+0.18%)
- unicode size=4096/array_utf8: 3.1ms → 3.1ms (0.00%)
- unicode size=4096/array_utf8view: 3.1ms → 3.1ms (0.00%)
- unicode size=8192/array_utf8: 6.2ms → 6.1ms (−1.61%)
- unicode size=8192/array_utf8view: 6.2ms → 6.2ms (0.00%)
## What changes are included in this PR?
* Switch to bulk-NULL string builders
* Optimize `StringViewArrayBuilder::append_value()` by inlining the view construction for > 12 byte strings. Empirically this improved performance, probably because `make_view` can't be inlined. This should also help other PRs in this series.
## Are these changes tested?
Yes, covered by existing tests.
## Are there any user-facing changes?
No.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Use bulk-NULL string builder in `initcap` [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #21863:
URL: https://github.com/apache/datafusion/pull/21863#discussion_r3147932453
##########
datafusion/functions/src/strings.rs:
##########
@@ -604,7 +604,17 @@ impl StringViewArrayBuilder {
let offset: u32 = i32::try_from(self.in_progress.len())
.expect("offset exceeds i32::MAX") as u32;
self.in_progress.extend_from_slice(v);
- self.views.push(make_view(v, buffer_index, offset));
+
+ // Build the ByteView inline rather than going through `make_view`,
+ // which is marked as `[inline(never)]`.
+ let view = ByteView {
+ length,
+ // SAFETY: length > 12 here, so v has at least 4 bytes.
Review Comment:
FWIW there is no safety implication here (as the code below uses unwrap() rather than `unsafe`)
##########
datafusion/functions/src/strings.rs:
##########
@@ -604,7 +604,17 @@ impl StringViewArrayBuilder {
let offset: u32 = i32::try_from(self.in_progress.len())
.expect("offset exceeds i32::MAX") as u32;
self.in_progress.extend_from_slice(v);
- self.views.push(make_view(v, buffer_index, offset));
+
+ // Build the ByteView inline rather than going through `make_view`,
Review Comment:
This might be worth a mention upstream in the docs -- I reacall this isn't inlined because for some really tight inner loops is messed up vectorization or something
But in general inlining probably helps (like maybe we should provide a version of `make_view` that is inlineable 🤔 )
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Use bulk-NULL string builder in `initcap` [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #21863:
URL: https://github.com/apache/datafusion/pull/21863#issuecomment-4327691101
I love how we are driving performance down bit by bit
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Use bulk-NULL string builder in `initcap` [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #21863:
URL: https://github.com/apache/datafusion/pull/21863
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org