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
Expand Up @@ -19,3 +19,6 @@
## 2026-07-13 - 단일 패스 문자열 치환 최적화 (O(N) 단일 스캔 및 지연 할당)
**Learning:** `String.replace()`를 여러 번 체이닝하여 호출하면, 문자열 치환이 발생하지 않는 경우에도 내부적으로 불필요한 스캔이 중복 발생하고, 치환 시마다 새로운 문자열 객체와 char 배열이 할당되어 메모리 낭비와 성능 저하(GC 압박)가 발생한다.
**Action:** 여러 문자를 한 번에 치환해야 하는 경우, O(N) 단일 스캔을 통해 `charAt()`으로 문자를 확인하고, 치환이 실제로 필요한 경우에만 `StringBuilder`를 지연 할당(Lazy allocation)하여 성능을 최적화하고 불필요한 메모리 할당을 방지한다.
## 2026-07-24 - File System Existence Check Overhead
**Learning:** Checking `Files.exists()` immediately before `Files.readAllBytes()` introduces an unnecessary Time-of-Check to Time-of-Use (TOCTOU) race condition and incurs an extra `stat` system call penalty on every read path.
**Action:** When performing local file I/O operations inside `try-catch` blocks, directly attempt the read operation (e.g., `Files.readAllBytes()`) and gracefully handle `java.nio.file.NoSuchFileException` to achieve better performance and eliminate the race condition.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -86,14 +87,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 (NoSuchFileException ex) {
return Optional.empty();
} catch (IOException ex) {
throw new IllegalStateException("failed to read artifact for docId " + docId, ex);
}
Expand Down
Loading