diff --git a/.jules/bolt.md b/.jules/bolt.md index ee124e69..6d2618cd 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -62,3 +62,6 @@ ## 2026-08-11 - Array의 toMutableList 할당 오버헤드 최적화 **학습:** 배열을 정렬하기 위해 `.toMutableList()`를 호출하면 새로운 `ArrayList` 객체와 내부 배열 객체가 할당되어 대규모 디렉토리를 순회할 때 가비지 컬렉션(GC) 부하를 유발합니다. 배열 복제가 필요한 경우 `.clone()`을 사용하면 하나의 배열 객체만 새로 할당되므로 더 효율적입니다. **조치:** 디렉토리 파일 배열을 정렬하기 전에 복사할 때 `.toMutableList()` 대신 `.clone()`을 사용하여 불필요한 중간 컬렉션 할당을 제거하고 성능을 향상시켰습니다. +## 2024-05-24 - Defer string allocations in loops +**Learning:** In hot loops, deferring expensive string allocations like `toLowerCase()` until after cheap, short-circuiting properties like `isHiddenFile()` or `endsWith()` can significantly reduce GC pressure. +**Action:** Always evaluate cheap checks first before transforming strings in loops. diff --git a/src/main/kotlin/html4tree/main.kt b/src/main/kotlin/html4tree/main.kt index 0972fa2c..f6bc50ae 100644 --- a/src/main/kotlin/html4tree/main.kt +++ b/src/main/kotlin/html4tree/main.kt @@ -351,11 +351,14 @@ fun process_ignore_file(curr_dir: File, dirFilesNames: Array? = null): S // 보안 향상: dot-like prefixes and case variants of known sensitive names are excluded. (dirFilesNames ?: curr_dir.list())?.forEach { + // ⚡ Bolt Performance Optimization: Defer expensive string allocations until after cheap short-circuit properties + if (it.isHiddenFile() || it.endsWith("~")) { + files_to_exclude.add(it) + return@forEach + } val normalizedName = it.toLowerCase(java.util.Locale.ROOT) if ( - it.isHiddenFile() || normalizedName in Constants.defaultSensitiveFileNamesLowercase || - normalizedName.endsWith("~") || Constants.defaultSensitiveExtensions.any { extension -> normalizedName.endsWith(extension) }