Document preview
+Preparing preview shell...
+ +Preview status
+ +Unable to load preview
+ +Preview
+ +When ready, the converted artifact will appear here.
+diff --git a/.jules/bolt.md b/.jules/bolt.md index 284d180..011e13d 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -19,3 +19,6 @@ ## 2026-07-13 - 단일 패스 문자열 치환 최적화 (O(N) 단일 스캔 및 지연 할당) **Learning:** `String.replace()`를 여러 번 체이닝하여 호출하면, 문자열 치환이 발생하지 않는 경우에도 내부적으로 불필요한 스캔이 중복 발생하고, 치환 시마다 새로운 문자열 객체와 char 배열이 할당되어 메모리 낭비와 성능 저하(GC 압박)가 발생한다. **Action:** 여러 문자를 한 번에 치환해야 하는 경우, O(N) 단일 스캔을 통해 `charAt()`으로 문자를 확인하고, 치환이 실제로 필요한 경우에만 `StringBuilder`를 지연 할당(Lazy allocation)하여 성능을 최적화하고 불필요한 메모리 할당을 방지한다. +## 2026-07-16 - HTML 템플릿 렌더링 시 문자열 치환 체이닝 오버헤드 방지 +**Learning:** 여러 번의 `.replace()` 호출을 체이닝하여 큰 HTML 템플릿에 동적 값을 주입하면 매 치환마다 중간 `String` 및 `char[]` 객체가 크게 할당되어 메모리 낭비와 성능 저하를 초래합니다. +**Action:** 큰 HTML 템플릿은 삽입될 위치를 기준으로 여러 개의 `private static final String` 조각으로 미리 분리하고, 단순히 `+` 연산자로 연결(StringBuilder로 자동 최적화됨)하여 불필요한 중간 객체 할당 없이 성능을 개선해야 합니다. diff --git a/src/main/java/com/clearfolio/viewer/controller/ViewerUiController.java b/src/main/java/com/clearfolio/viewer/controller/ViewerUiController.java index 5e7de3c..de0422c 100644 --- a/src/main/java/com/clearfolio/viewer/controller/ViewerUiController.java +++ b/src/main/java/com/clearfolio/viewer/controller/ViewerUiController.java @@ -20,6 +20,82 @@ public class ViewerUiController { static final String PDF_JS_VIEWER_PATH = "/webjars/pdfjs-dist/4.10.38/web/viewer.html"; private static final String INVALID_DOC_ID_SENTINEL = "invalid"; + // Pre-allocated template parts for viewer shell HTML + private static final String VIEWER_HTML_PART_1 = """ + + +
+ + + + + + +Preparing preview shell...
+ +When ready, the converted artifact will appear here.
+Preparing preview shell...
- -When ready, the converted artifact will appear here.
-