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
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@
## 2026-07-13 - 단일 패스 문자열 치환 최적화 (O(N) 단일 스캔 및 지연 할당)
**Learning:** `String.replace()`를 여러 번 체이닝하여 호출하면, 문자열 치환이 발생하지 않는 경우에도 내부적으로 불필요한 스캔이 중복 발생하고, 치환 시마다 새로운 문자열 객체와 char 배열이 할당되어 메모리 낭비와 성능 저하(GC 압박)가 발생한다.
**Action:** 여러 문자를 한 번에 치환해야 하는 경우, O(N) 단일 스캔을 통해 `charAt()`으로 문자를 확인하고, 치환이 실제로 필요한 경우에만 `StringBuilder`를 지연 할당(Lazy allocation)하여 성능을 최적화하고 불필요한 메모리 할당을 방지한다.

## 2024-07-28 - I/O 성능 최적화: TOCTOU 방지
**Learning:** `Files.exists()`를 먼저 호출하고 파일을 읽는 것은 디스크 접근을 두 번 하게 만들 뿐만 아니라 TOCTOU (Time-Of-Check to Time-Of-Use) 경쟁 조건을 발생시킬 수 있다.
**Action:** 파일이 존재하지 않는 것을 처리해야 할 경우, 파일을 직접 읽은 뒤 발생하는 `java.nio.file.NoSuchFileException`을 잡아서 처리하도록 하여 디스크 I/O를 줄이고 성능을 향상시킨다.
Comment on lines +23 to +25
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,13 @@ public Optional<byte[]> getPdf(UUID docId) {
}

Path pdfPath = pdfPath(docId);
if (!Files.exists(pdfPath)) {
return Optional.empty();
}

try {
byte[] loaded = bytesReader.read(pdfPath);
cache.put(docId, loaded);
return Optional.of(loaded.clone());
} catch (java.nio.file.NoSuchFileException ex) {
return Optional.empty();
} catch (IOException ex) {
throw new IllegalStateException("failed to read artifact for docId " + docId, ex);
}
Expand Down
Loading