From 85bf2a8cca66324b66aca2ba6cc5a186b18bfcd8 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sun, 28 Jun 2026 21:15:37 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Hex=20=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=EC=97=B4=20=EB=B3=80=ED=99=98=20=EC=84=B1=EB=8A=A5=20?= =?UTF-8?q?=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DefaultDocumentConversionService에서 바이트 배열을 Hex 문자열로 변환할 때 String.format을 루프 안에서 사용하는 비효율적인 방식을 java.util.HexFormat.of().formatHex(raw)로 변경하여 성능을 최적화했습니다. --- .jules/bolt.md | 3 +++ CHANGELOG.md | 5 +++++ .../viewer/service/DefaultDocumentConversionService.java | 8 ++------ 3 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 .jules/bolt.md create mode 100644 CHANGELOG.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..0eed87b3 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2026-06-28 - Fast Hex String Conversion +**Learning:** Using `String.format("%02x", b)` inside a loop for converting byte arrays to hex strings is a significant performance bottleneck due to string parsing overhead per byte. +**Action:** Use `java.util.HexFormat.of().formatHex(bytes)` instead for a massive performance improvement when converting byte arrays to hex strings in Java 17+. diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..78e15496 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# 변경 사항 + +## [Unreleased] +### 성능 개선 (Performance) +- `DefaultDocumentConversionService` 내부의 `String.format` 루프를 사용하던 비효율적인 Hex 문자열 변환 로직을 `java.util.HexFormat`을 사용하도록 변경하여 성능 크게 최적화 diff --git a/src/main/java/com/clearfolio/viewer/service/DefaultDocumentConversionService.java b/src/main/java/com/clearfolio/viewer/service/DefaultDocumentConversionService.java index 9c595937..221fb175 100644 --- a/src/main/java/com/clearfolio/viewer/service/DefaultDocumentConversionService.java +++ b/src/main/java/com/clearfolio/viewer/service/DefaultDocumentConversionService.java @@ -121,12 +121,8 @@ 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(); + // HexFormat is faster than String.format + return java.util.HexFormat.of().formatHex(raw); } catch (NoSuchAlgorithmException ex) { throw new IllegalStateException("SHA-256 digest unavailable", ex); } catch (IOException ex) { From ce2ecf9070fd5d389ea464ae3050c43226a62e26 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sun, 28 Jun 2026 22:04:37 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Hex=20=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=EC=97=B4=20=EB=B3=80=ED=99=98=20=EC=84=B1=EB=8A=A5=20?= =?UTF-8?q?=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DefaultDocumentConversionService에서 바이트 배열을 Hex 문자열로 변환할 때 String.format을 루프 안에서 사용하는 비효율적인 방식을 java.util.HexFormat.of().formatHex(raw)로 변경하여 성능을 최적화했습니다. From de2fad1fc882e6bf308206816e05dcc70439828b Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sun, 28 Jun 2026 22:39:48 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Hex=20=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=EC=97=B4=20=EB=B3=80=ED=99=98=20=EC=84=B1=EB=8A=A5=20?= =?UTF-8?q?=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DefaultDocumentConversionService에서 바이트 배열을 Hex 문자열로 변환할 때 String.format을 루프 안에서 사용하는 비효율적인 방식을 java.util.HexFormat.of().formatHex(raw)로 변경하여 성능을 최적화했습니다. From eb94129ef4af05ecbed04cc2af69221e24ecedf0 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Mon, 29 Jun 2026 00:11:14 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Hex=20=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=EC=97=B4=20=EB=B3=80=ED=99=98=20=EC=84=B1=EB=8A=A5=20?= =?UTF-8?q?=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DefaultDocumentConversionService에서 바이트 배열을 Hex 문자열로 변환할 때 String.format을 루프 안에서 사용하는 비효율적인 방식을 java.util.HexFormat.of().formatHex(raw)로 변경하여 성능을 최적화했습니다.