Skip to content

Perf: remove extra allocations for hex operations - #24057

Merged
alamb merged 5 commits into
apache:mainfrom
Rich-T-kid:rich-T-kid/avoid-hex-string-allocation
Aug 15, 2026
Merged

Perf: remove extra allocations for hex operations#24057
alamb merged 5 commits into
apache:mainfrom
Rich-T-kid:rich-T-kid/avoid-hex-string-allocation

Conversation

@Rich-T-kid

@Rich-T-kid Rich-T-kid commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

The digest functions hex-encode their output by allocating one String per row and then copying each of those into the output array (#23810)

What changes are included in this PR?

  • This PR reduces per-row allocation and string-conversion overhead in the Spark crypto/hash paths by switching to the buffer-based hex encoder APIs.
  • Updates call sites to re-use vector buffers.

Are these changes tested?

existing test cover behavior.

Are there any user-facing changes?

yes, encode_bytes() is being deprecated. This was apart of the public API

@github-actions github-actions Bot added functions Changes to functions implementation spark labels Aug 3, 2026
@Rich-T-kid
Rich-T-kid force-pushed the rich-T-kid/avoid-hex-string-allocation branch from edfa6cf to 15d22de Compare August 3, 2026 05:27
@github-actions github-actions Bot added the common Related to common crate label Aug 3, 2026
@Rich-T-kid
Rich-T-kid marked this pull request as ready for review August 3, 2026 05:31
@github-actions github-actions Bot added the auto detected api change Auto detected API change label Aug 3, 2026

@Rich-T-kid Rich-T-kid left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may not need to deprecate this — just swapping out how DataFusion uses this internally may be enough, and it avoids a breaking API change.

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author
Image 8-3-26 at 1 49 AM local benchmarks show promising results

@Rich-T-kid
Rich-T-kid force-pushed the rich-T-kid/avoid-hex-string-allocation branch from 15d22de to 67cb73d Compare August 3, 2026 05:55
@Rich-T-kid
Rich-T-kid force-pushed the rich-T-kid/avoid-hex-string-allocation branch from 67cb73d to 4b880e1 Compare August 3, 2026 05:56
@codecov-commenter

codecov-commenter commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.14%. Comparing base (21ad189) to head (c8dd962).
⚠️ Report is 137 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24057      +/-   ##
==========================================
+ Coverage   80.88%   81.14%   +0.26%     
==========================================
  Files        1101     1110       +9     
  Lines      375720   386233   +10513     
  Branches   375720   386233   +10513     
==========================================
+ Hits       303895   313420    +9525     
- Misses      53729    54353     +624     
- Partials    18096    18460     +364     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread datafusion/common/src/utils/hex.rs Outdated
Comment thread datafusion/functions/src/encoding/inner.rs Outdated
@Rich-T-kid
Rich-T-kid requested a review from Jefffrey August 13, 2026 03:49
@github-actions github-actions Bot removed the auto detected api change Auto detected API change label Aug 13, 2026
@alamb
alamb added this pull request to the merge queue Aug 15, 2026

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me too -- thank you @Rich-T-kid and @Jefffrey

Merged via the queue into apache:main with commit a10d193 Aug 15, 2026
37 checks passed
imtherealnaska pushed a commit to imtherealnaska/datafusion that referenced this pull request Aug 16, 2026
## 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. For example
`Closes apache#123` indicates that this PR will close issue apache#123.
-->

- Closes apache#23810.

## Rationale for this change
The digest functions hex-encode their output by allocating one String
per row and then copying each of those into the output array (apache#23810)
<!--
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?

- This PR reduces per-row allocation and string-conversion overhead in
the Spark crypto/hash paths by switching to the buffer-based hex encoder
APIs.
- Updates call sites to re-use vector buffers.

<!--
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?
existing test cover behavior.
<!--
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)?
-->

## Are there any user-facing changes?
yes, `encode_bytes()` is being deprecated. This was apart of the public
API
<!--
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 add the `api
change` label.
-->

---------

Co-authored-by: rich-T-kid <richardbaah@MacBook-Air-de-Richard.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate functions Changes to functions implementation spark

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid per-row String allocation when hex-encoding digest output (md5, sha1, sha2)

4 participants