diff --git a/.jules/bolt.md b/.jules/bolt.md index ee124e69..61f84777 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -62,3 +62,7 @@ ## 2026-08-11 - Array의 toMutableList 할당 오버헤드 최적화 **학습:** 배열을 정렬하기 위해 `.toMutableList()`를 호출하면 새로운 `ArrayList` 객체와 내부 배열 객체가 할당되어 대규모 디렉토리를 순회할 때 가비지 컬렉션(GC) 부하를 유발합니다. 배열 복제가 필요한 경우 `.clone()`을 사용하면 하나의 배열 객체만 새로 할당되므로 더 효율적입니다. **조치:** 디렉토리 파일 배열을 정렬하기 전에 복사할 때 `.toMutableList()` 대신 `.clone()`을 사용하여 불필요한 중간 컬렉션 할당을 제거하고 성능을 향상시켰습니다. + +## 2026-09-15 - [문자열 조회 최적화를 통한 성능 향상] +**Learning:** `when (firstOrNull())`을 사용하면 핫 루프에서 문자를 확인할 때 객체 할당 오버헤드가 발생합니다. +**Action:** 빠른 불리언 평가를 위해 `firstOrNull()` 시퀀스 대신 길이를 명시적으로 검사하고 인덱스 0에 직접 접근합니다. diff --git a/CHANGELOG.md b/CHANGELOG.md index c442b3b1..30bb477e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to this project are documented in this file. ### Added +- **Performance**: 문자열의 `isHiddenFile` 함수 내 객체 할당(sequence materialization) 제거 + - Emit a `noindex, nofollow` robots meta preference on every generated directory page, with the explicit boundary that supporting crawlers must first fetch the page and that confidential data still requires server-side diff --git a/patch_main_comment.patch b/patch_main_comment.patch new file mode 100644 index 00000000..dd8cf685 --- /dev/null +++ b/patch_main_comment.patch @@ -0,0 +1,12 @@ +--- src/main/kotlin/html4tree/main.kt ++++ src/main/kotlin/html4tree/main.kt +@@ -223,8 +223,10 @@ + } + + fun String.isHiddenFile(): Boolean { ++ // ⚡ Bolt Performance Optimization: Replace firstOrNull() with isEmpty() + this[0] ++ // avoiding Char? boxing and object allocation in a hot loop directory enumeration. + if (this.isEmpty()) return false + val c = this[0] + return c == '.' || c == '\u3002' || c == '\uFF0E' || c == '\uFF61' + } diff --git a/src/main/kotlin/html4tree/main.kt b/src/main/kotlin/html4tree/main.kt index 0972fa2c..dbc0c72c 100644 --- a/src/main/kotlin/html4tree/main.kt +++ b/src/main/kotlin/html4tree/main.kt @@ -223,10 +223,11 @@ internal fun crawl_directories( } fun String.isHiddenFile(): Boolean { - return when (firstOrNull()) { - '.', '\u3002', '\uFF0E', '\uFF61' -> true - else -> false - } + // ⚡ Bolt Performance Optimization: Replace firstOrNull() with isEmpty() + this[0] + // avoiding Char? boxing and object allocation in a hot loop directory enumeration. + if (this.isEmpty()) return false + val c = this[0] + return c == '.' || c == '\u3002' || c == '\uFF0E' || c == '\uFF61' } // ⚡ Bolt Performance Optimization: Single-pass loop with lazy StringBuilder diff --git a/src/test/kotlin/html4tree/IsHiddenFileTest.kt b/src/test/kotlin/html4tree/IsHiddenFileTest.kt new file mode 100644 index 00000000..9800d58c --- /dev/null +++ b/src/test/kotlin/html4tree/IsHiddenFileTest.kt @@ -0,0 +1,18 @@ +package html4tree + +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class IsHiddenFileTest { + + @Test + fun `isHiddenFile should correctly identify hidden files`() { + assertTrue(".hidden".isHiddenFile()) + assertTrue("\u3002hidden".isHiddenFile()) + assertTrue("\uFF0Ehidden".isHiddenFile()) + assertTrue("\uFF61hidden".isHiddenFile()) + assertFalse("normal.txt".isHiddenFile()) + assertFalse("".isHiddenFile()) + } +}