From 7a1a65bedf9e2b848b7500e441245e329c99dca6 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sun, 9 Aug 2026 03:34:02 +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=EA=B3=A0=EC=A0=95=20=EC=BB=AC=EB=A0=89?= =?UTF-8?q?=EC=85=98=20=EB=B0=8F=20Comparator=20=ED=95=A0=EB=8B=B9=20?= =?UTF-8?q?=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/bolt.md | 3 +++ src/main/kotlin/html4tree/main.kt | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 19b4c613..a13aa826 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -43,3 +43,6 @@ ## 2025-01-24 - 단일 readAttributes 호출로 파일 속성 조회 최적화 **학습:** `isDirectory`, `!it.isDirectory()`, `isSymbolicLink` 3개의 개별적인 파일 시스템 I/O 호출을 수행하면 성능 저하가 큽니다. 이를 단일 `Files.readAttributes` 호출로 변경하여 메타데이터를 한 번에 조회함으로써 I/O 오버헤드를 대폭 줄일 수 있음을 확인했습니다. **조치:** 디렉토리 순회 시 파일의 여러 속성을 확인할 때는 개별적인 stat 호출보다 `Files.readAttributes`를 사용하여 필요한 모든 속성을 한 번에 가져오는 방식을 우선적으로 고려해야 합니다. +## 2026-08-09 - 잦은 호출 함수 내 고정 컬렉션 및 Comparator 할당 최적화 +**학습:** `process_ignore_file` 내 `listOf` 및 `process_dir` 내 `compareBy`와 같이 자주 호출되는 함수 내부에서 객체를 반복 할당하면 불필요한 성능 및 메모리 오버헤드가 발생합니다. +**조치:** 불변 정적 문자열, 컬렉션 및 람다(Comparator 등)는 최상단 `private val` 상수로 호이스팅(hoisting)하여 객체 할당을 한 번으로 줄입니다. diff --git a/src/main/kotlin/html4tree/main.kt b/src/main/kotlin/html4tree/main.kt index f52a1468..7866d8d9 100644 --- a/src/main/kotlin/html4tree/main.kt +++ b/src/main/kotlin/html4tree/main.kt @@ -95,6 +95,12 @@ li + li { private val STYLE_HASH = "sha256-" + Base64.getEncoder().encodeToString(MessageDigest.getInstance("SHA-256").digest(CSS_CONTENT.toByteArray(Charsets.UTF_8))) +// ⚡ Bolt Performance Optimization: Hoist invariant static collections to prevent redundant allocations +private val DEFAULT_SENSITIVE_FILES = listOf(".git", ".env", ".ssh", ".htpasswd", ".htaccess", "id_rsa", "id_ed25519", "secrets.yml", ".html4ignore", ".DS_Store", ".aws", ".kube", ".npmrc", ".gnupg", "config.json", "credentials.json") + +// ⚡ Bolt Performance Optimization: Hoist Comparator to prevent redundant object allocations on each sorting call +private val FILE_NAME_COMPARATOR = compareBy { it.name } + class Html4tree : CliktCommand() { val maxLevel:Int by option(help="Number of levels deep for which to generate an index.html file", hidden = false).int().default(-1) val topDir: String by argument(help="Top directory to crawl") @@ -298,8 +304,7 @@ fun process_ignore_file(curr_dir: File, dirFilesNames: Array? = null): S files_to_exclude.add("index.html") // 보안 향상: 민감한 시스템, 설정, 시크릿 파일을 디렉토리 목록에서 기본적으로 제외하여 정보 노출(Information Exposure) 방지 - val defaultSensitiveFiles = listOf(".git", ".env", ".ssh", ".htpasswd", ".htaccess", "id_rsa", "id_ed25519", "secrets.yml", ".html4ignore", ".DS_Store", ".aws", ".kube", ".npmrc", ".gnupg", "config.json", "credentials.json") - files_to_exclude.addAll(defaultSensitiveFiles) + files_to_exclude.addAll(DEFAULT_SENSITIVE_FILES) // 보안 향상: .env, .git 등 민감한 정보가 포함될 수 있는 숨김 파일(.으로 시작하는 모든 항목)을 기본적으로 노출하지 않도록 제외 (정보 노출 방지) (dirFilesNames ?: curr_dir.list())?.forEach { @@ -352,7 +357,7 @@ fun process_dir(curr_dir: File, excludeSet: Set? = null, dirFiles: Array val filesList = dirFiles ?: curr_dir.listFiles() val dir_files: MutableList = filesList?.toMutableList() ?: mutableListOf() - dir_files.sortWith(compareBy ({it.name}) ) + dir_files.sortWith(FILE_NAME_COMPARATOR) dir_files.forEach { val fileName = it.getName() // ⚡ Bolt Performance Optimization: Short-circuit string match before expensive OS filesystem calls