Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-06-27 - HexFormat Optimization
**Learning:** Using `String.format("%02x", b)` in a loop for byte to hex conversion creates significant overhead due to excessive object allocations and parsing.
**Action:** Always prefer `java.util.HexFormat.of().formatHex(raw)` introduced in Java 17 for byte array to hex string conversions, as it is highly optimized and avoids unnecessary object creation.
Original file line number Diff line number Diff line change
Expand Up @@ -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 Optimization: Use java.util.HexFormat instead of
// String.format in loop to eliminate excessive object allocation
// overhead and significantly speed up hex string conversion.
return java.util.HexFormat.of().formatHex(raw);
} catch (NoSuchAlgorithmException ex) {
throw new IllegalStateException("SHA-256 digest unavailable", ex);
} catch (IOException ex) {
Expand Down
Loading