diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..4168133 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2026-07-01 - Byte Array to Hex String Conversion Optimization +**Learning:** In Java 21, using `String.format("%02x", b)` inside a loop to convert a byte array to a hex string causes unnecessary allocations and is significantly slower than native alternatives. +**Action:** Use `java.util.HexFormat.of().formatHex(bytes)` for faster and allocation-free conversions from byte arrays to hex strings in this codebase. diff --git a/src/main/java/com/clearfolio/viewer/service/DefaultDocumentConversionService.java b/src/main/java/com/clearfolio/viewer/service/DefaultDocumentConversionService.java index 9c59593..c0335f9 100644 --- a/src/main/java/com/clearfolio/viewer/service/DefaultDocumentConversionService.java +++ b/src/main/java/com/clearfolio/viewer/service/DefaultDocumentConversionService.java @@ -121,12 +121,10 @@ private String contentHash(MultipartFile file) { } byte[] raw = digest.digest(); - StringBuilder hex = new StringBuilder(raw.length * 2); - for (byte b : raw) { - hex.append(String.format("%02x", b)); - } - return hex.toString(); + // Bolt Performance Optimization: + // Use HexFormat instead of String.format loop for performance. + return java.util.HexFormat.of().formatHex(raw); } catch (NoSuchAlgorithmException ex) { throw new IllegalStateException("SHA-256 digest unavailable", ex); } catch (IOException ex) {