Skip to content
Draft
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@
## 2026-08-11 - Array의 toMutableList 할당 오버헤드 최적화
**학습:** 배열을 정렬하기 위해 `.toMutableList()`를 호출하면 새로운 `ArrayList` 객체와 내부 배열 객체가 할당되어 대규모 디렉토리를 순회할 때 가비지 컬렉션(GC) 부하를 유발합니다. 배열 복제가 필요한 경우 `.clone()`을 사용하면 하나의 배열 객체만 새로 할당되므로 더 효율적입니다.
**조치:** 디렉토리 파일 배열을 정렬하기 전에 복사할 때 `.toMutableList()` 대신 `.clone()`을 사용하여 불필요한 중간 컬렉션 할당을 제거하고 성능을 향상시켰습니다.

## 2026-09-26 - 조건 분기 전 불필요한 문자열 할당 지연 (Lazy Allocation)
**Learning:** `process_ignore_file` 내에서 디렉토리 목록을 순회할 때, 파일이 숨김 파일이거나 틸드(`~`)로 끝나는지 검사하는 저렴한 조건보다 앞서 무조건 `it.toLowerCase()`를 호출하여 새로운 문자열 객체를 할당하는 오버헤드가 있었습니다.
**Action:** 논리합(`||`) 연산자의 단락 평가(short-circuit) 특성을 활용하여, 할당 비용이 없는 단순 문자열/문자 검사를 먼저 수행하도록 순서를 변경했습니다. 이를 통해 해당 조건을 만족하는 파일에 대해서는 `toLowerCase()` 할당을 지연(건너뛰기)하여 GC 부하를 줄일 수 있습니다.
11 changes: 6 additions & 5 deletions src/main/kotlin/html4tree/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,14 @@ fun process_ignore_file(curr_dir: File, dirFilesNames: Array<String>? = null): S

// 보안 향상: dot-like prefixes and case variants of known sensitive names are excluded.
(dirFilesNames ?: curr_dir.list())?.forEach {
val normalizedName = it.toLowerCase(java.util.Locale.ROOT)
// ⚡ Bolt Performance Optimization: Delay expensive string allocation (toLowerCase)
// Check cheap conditions first before allocating a new lowercase string for every file
if (
it.isHiddenFile() ||
normalizedName in Constants.defaultSensitiveFileNamesLowercase ||
normalizedName.endsWith("~") ||
Constants.defaultSensitiveExtensions.any { extension ->
normalizedName.endsWith(extension)
it.endsWith("~") ||
it.toLowerCase(java.util.Locale.ROOT).let { normalizedName ->
normalizedName in Constants.defaultSensitiveFileNamesLowercase ||
Constants.defaultSensitiveExtensions.any { extension -> normalizedName.endsWith(extension) }
}
) {
files_to_exclude.add(it)
Expand Down
Loading
Loading