From 27a34bc9593c68e7bcdb61ac76f2aeb6b74490d6 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Wed, 1 Jul 2026 20:53:22 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Byte=20=EB=B0=B0=EC=97=B4?= =?UTF-8?q?=20=ED=97=A5=EC=8A=A4=20=EB=AC=B8=EC=9E=90=EC=97=B4=20=EB=B3=80?= =?UTF-8?q?=ED=99=98=20=EC=84=B1=EB=8A=A5=20=EC=B5=9C=EC=A0=81=ED=99=94=20?= =?UTF-8?q?(HexFormat=20=EC=A0=81=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/bolt.md | 3 +++ .../viewer/service/DefaultDocumentConversionService.java | 8 +++----- 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 .jules/bolt.md 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) {