-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-48596][SQL] Perf improvement for calculating hex string for long #46952
Conversation
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add comments to explain the arithmetic expression ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the necessity for commenting on such a pretty common expression
@@ -1018,9 +1018,9 @@ case class Bin(child: Expression) | |||
} | |||
|
|||
object Hex { | |||
val hexDigits = Array[Char]( | |||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' | |||
).map(_.toByte) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
do { | ||
len += 1 | ||
value(value.length - len) = Hex.hexDigits((numBuf & 0xF).toInt) | ||
val value = new Array[Byte](len) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value
-> bytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bytes might be good but the naming is currently consistent with another variant.
cc @cloud-fan @dongjoon-hyun @LuciferYang thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, LGTM
Merged to master. Thank you @LuciferYang and also for the offline suggestion |
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