Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@
## 2025-01-24 - 단일 readAttributes 호출로 파일 속성 조회 최적화 (순회 루프)
**학습:** 디렉토리 순회 루프 내에서 isDirectory 및 isSymbolicLink 두 번의 stat을 각각 호출하면 파일 시스템 I/O 오버헤드가 배가됩니다. 메모리 내 제외 규칙 확인 후 한 번의 readAttributes로 속성을 한 번에 가져오는 것이 훨씬 빠릅니다.
**조치:** Files.isDirectory 및 Files.isSymbolicLink를 단일 Files.readAttributes 호출로 교체하여 O(N) I/O 통신을 최적화했습니다.
## 2025-01-25 - Comparator 객체 생성 방지 (루프 외부 할당)
**학습:** Kotlin에서 `compareBy { it.name }`를 루프 내부에서 또는 빈번하게 호출되는 함수에서 사용할 경우 매 호출마다 새로운 `Comparator` 객체가 할당되어 성능 및 가비지 컬렉션(GC) 압력이 발생합니다.
**조치:** 빈번한 정렬 작업에 사용되는 Comparator를 최상위 레벨의 `private val` 상수로 호이스팅(hoisting)하여 매번 새롭게 객체가 생성되는 것을 방지합니다.
3 changes: 2 additions & 1 deletion src/main/kotlin/html4tree/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ li + li {
""".trimIndent()

private val STYLE_HASH = "sha256-" + Base64.getEncoder().encodeToString(MessageDigest.getInstance("SHA-256").digest(CSS_CONTENT.toByteArray(Charsets.UTF_8)))
private val FILE_NAME_COMPARATOR = compareBy<File> { 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)
Expand Down Expand Up @@ -368,7 +369,7 @@ fun process_dir(curr_dir: File, excludeSet: Set<String>? = null, dirFiles: Array

val filesList = dirFiles ?: curr_dir.listFiles()
val dir_files: MutableList<File> = 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
Expand Down
Loading