comphead commented on code in PR #19568:
URL: https://github.com/apache/datafusion/pull/19568#discussion_r2653906392


##########
datafusion/functions/src/crypto/basic.rs:
##########
@@ -157,14 +157,18 @@ pub fn md5(args: &[ColumnarValue]) -> 
Result<ColumnarValue> {
     })
 }
 
-/// this function exists so that we do not need to pull in the crate hex. it 
is only used by md5
-/// function below
+/// Hex encoding lookup table for fast byte-to-hex conversion
+const HEX_CHARS_LOWER: &[u8; 16] = b"0123456789abcdef";
+
+/// Fast hex encoding using a lookup table instead of format strings.
+/// This is significantly faster than using `write!("{:02x}")` for each byte.
 #[inline]
 fn hex_encode<T: AsRef<[u8]>>(data: T) -> String {

Review Comment:
   great, curious if that would be more performance if create a string directly 
from bytes without utf checks(which is redundant ) and extract casts?
   
   ```
   let bytes = data.as_ref();
   let mut out = Vec::with_capacity(bytes.len() * 2);
   
   for &b in bytes {
           out.push(HEX_CHARS_LOWER[(b >> 4) as usize]);
           out.push(HEX_CHARS_LOWER[(b & 0x0f) as usize]);
   }
   
   unsafe { String::from_utf8_unchecked(out) }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to