From 9bc3568b12d9e9267d5341b703d2d6c1bcd74c06 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Thu, 17 Sep 2026 03:23:37 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[=EC=84=B1=EB=8A=A5=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0]=20=ED=95=AB=20=EB=A3=A8=ED=94=84=20?= =?UTF-8?q?=EB=82=B4=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=EC=97=B4=20=ED=95=A0=EB=8B=B9=20=EC=A7=80=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - isHiddenFile 및 endsWith("~") 검사 후 toLowerCase 호출 --- .jules/bolt.md | 4 ++++ src/main/kotlin/html4tree/main.kt | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index ee124e69..102824b1 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -62,3 +62,7 @@ ## 2026-08-11 - Array의 toMutableList 할당 오버헤드 최적화 **학습:** 배열을 정렬하기 위해 `.toMutableList()`를 호출하면 새로운 `ArrayList` 객체와 내부 배열 객체가 할당되어 대규모 디렉토리를 순회할 때 가비지 컬렉션(GC) 부하를 유발합니다. 배열 복제가 필요한 경우 `.clone()`을 사용하면 하나의 배열 객체만 새로 할당되므로 더 효율적입니다. **조치:** 디렉토리 파일 배열을 정렬하기 전에 복사할 때 `.toMutableList()` 대신 `.clone()`을 사용하여 불필요한 중간 컬렉션 할당을 제거하고 성능을 향상시켰습니다. + +## 2024-10-24 - 핫 루프 내 문자열 할당 지연 최적화 +**학습:** 디렉토리 순회와 같은 핫 루프 내에서 파일 이름을 검사할 때, `.toLowerCase()`와 같은 문자열 할당 함수를 조기에 호출하면 가비지 컬렉션(GC) 압력을 증가시키고 성능을 저하시킵니다. `isHiddenFile()`이나 `.endsWith("~")`과 같은 저렴한 연산을 먼저 수행하면 불필요한 할당을 피할 수 있습니다. +**조치:** 무거운 작업(문자열 할당)을 루프 초기에 수행하는 대신, 저렴하고 조기 종료가 가능한 조건(`isHiddenFile()` 등)을 먼저 검사한 후, 그 조건에 맞지 않을 때만 무거운 작업을 수행하도록 `if-else` 블록 또는 지연 평가를 사용합니다. diff --git a/src/main/kotlin/html4tree/main.kt b/src/main/kotlin/html4tree/main.kt index 0972fa2c..636a5218 100644 --- a/src/main/kotlin/html4tree/main.kt +++ b/src/main/kotlin/html4tree/main.kt @@ -351,16 +351,20 @@ 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 { - val normalizedName = it.toLowerCase(java.util.Locale.ROOT) - if ( - it.isHiddenFile() || - normalizedName in Constants.defaultSensitiveFileNamesLowercase || - normalizedName.endsWith("~") || - Constants.defaultSensitiveExtensions.any { extension -> - normalizedName.endsWith(extension) - } - ) { + // ⚡ Bolt Performance Optimization: Defer expensive string allocation (toLowerCase) + // after evaluating cheap, short-circuiting properties to reduce GC pressure. + if (it.isHiddenFile() || it.endsWith("~")) { files_to_exclude.add(it) + } else { + val normalizedName = it.toLowerCase(java.util.Locale.ROOT) + if ( + normalizedName in Constants.defaultSensitiveFileNamesLowercase || + Constants.defaultSensitiveExtensions.any { extension -> + normalizedName.endsWith(extension) + } + ) { + files_to_exclude.add(it) + } } }