You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2026/07/17 15:18:37 UTC
[I] Further optimize Spark hex byte encoding: reuse input NullBuffer and special-case the no-nulls path [datafusion]
andygrove opened a new issue, #23674:
URL: https://github.com/apache/datafusion/issues/23674
### Is your feature request related to a problem or challenge?
Follow-on from review feedback on #23473, which rewrote `hex_encode_bytes` (`datafusion/spark/src/function/math/hex.rs`) to write hex digits directly into a single value buffer. Two further optimizations were suggested during review but left out of that PR to keep it focused:
1. **Reuse the input `NullBuffer` instead of rebuilding one.** The current implementation constructs a fresh `NullBufferBuilder` and calls `append_null`/`append_non_null` per row. Since hex encoding is 1:1 with the input rows (a null in maps to a null out), the output nulls are identical to the input's. We could clone the input array's `NullBuffer` directly instead of rebuilding it. This requires plumbing the input array (or its nulls) through to `hex_encode_bytes`, which currently only receives an `Iterator<Item = Option<T>>` and has no access to the underlying `NullBuffer`.
> we can probably avoid a null builder by just cloning the input nulls? though i guess need to plumb the functions to pass those through
> — @Jefffrey, https://github.com/apache/datafusion/pull/23473#discussion_r3577957866
2. **Special-case the "no nulls" path.** When the input `NullBuffer` is `None`, there is no need to check each value for `Some`/`None`. We could split into two loops — one tight loop for the no-nulls case and one for the has-nulls case.
> Another optimization is to special case the "has nulls" path (aka if the input NullBuffer is None, there is no need to check each value for `Some` / `None` too -- instead we could have two loops
> — @alamb, https://github.com/apache/datafusion/pull/23473#discussion_r3597744534
### Describe the solution you'd like
Refactor `hex_encode_bytes` in `datafusion/spark/src/function/math/hex.rs` to:
- Accept the input array (or its `NullBuffer`) so the output nulls can be cloned directly rather than rebuilt via `NullBufferBuilder`.
- Take separate code paths for the no-nulls and has-nulls cases, avoiding a per-value `Option` check when the input has no nulls.
Validate with the existing `datafusion/spark/benches/hex.rs` benchmark against `main`.
### Describe alternatives you've considered
Leaving the implementation as-is; it already avoids the per-row copy that #23473 targeted. These are incremental improvements on top of that.
### Additional context
Both suggestions came from review of #23473.
--
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.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: [I] Further optimize Spark hex byte encoding: reuse input NullBuffer and special-case the no-nulls path [datafusion]
Posted by "nerdyinu (via GitHub)" <gi...@apache.org>.
nerdyinu commented on issue #23674:
URL: https://github.com/apache/datafusion/issues/23674#issuecomment-5032052626
take
--
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: [I] Further optimize Spark hex byte encoding: reuse input NullBuffer and special-case the no-nulls path [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #23674:
URL: https://github.com/apache/datafusion/issues/23674#issuecomment-5006953242
i think this is a good first issue as it is quite well specified
--
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: [I] Further optimize Spark hex byte encoding: reuse input NullBuffer and special-case the no-nulls path [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew closed issue #23674: Further optimize Spark hex byte encoding: reuse input NullBuffer and special-case the no-nulls path
URL: https://github.com/apache/datafusion/issues/23674
--
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