[SPARK-48596][SQL] Perf improvement for calculating hex string for long#46952
Closed
yaooqinn wants to merge 3 commits into
Closed
[SPARK-48596][SQL] Perf improvement for calculating hex string for long#46952yaooqinn wants to merge 3 commits into
yaooqinn wants to merge 3 commits into
Conversation
beliefer
reviewed
Jun 12, 2024
| val value = new Array[Byte](16) | ||
| val zeros = jl.Long.numberOfLeadingZeros(num) | ||
| if (zeros == jl.Long.SIZE) return ZERO_UTF8 | ||
| val len = (jl.Long.SIZE - zeros + 3) / 4 |
Contributor
There was a problem hiding this comment.
Could you add comments to explain the arithmetic expression ?
Member
Author
There was a problem hiding this comment.
I don't see the necessity for commenting on such a pretty common expression
beliefer
reviewed
Jun 12, 2024
| object Hex { | ||
| val hexDigits = Array[Char]( | ||
| '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' | ||
| ).map(_.toByte) |
| do { | ||
| len += 1 | ||
| value(value.length - len) = Hex.hexDigits((numBuf & 0xF).toInt) | ||
| val value = new Array[Byte](len) |
Member
Author
There was a problem hiding this comment.
bytes might be good but the naming is currently consistent with another variant.
Member
Author
|
cc @cloud-fan @dongjoon-hyun @LuciferYang thanks |
Member
Author
|
Merged to master. Thank you @LuciferYang and also for the offline suggestion |
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.
What changes were proposed in this pull request?
This pull request optimizes the
Hex.hex(num: Long)method by removing leading zeros, thus eliminating the need to copy the array to remove them afterward.Why are the changes needed?
Does this PR introduce any user-facing change?
no
How was this patch tested?
Was this patch authored or co-authored using generative AI tooling?
no