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 @@ -12,3 +12,6 @@
## 2024-07-08 - URL Encoding String Allocation Bottleneck
**Learning:** `byte.toString(16).padStart(2, '0').toUpperCase()` inside a loop allocating up to 3 strings per reserved byte in a hot path causes significant GC pressure. This is a common but dangerous anti-pattern in Kotlin when processing large strings or numerous files in directory crawlers.
**Action:** Replace chained string operations with direct character mapping and bitwise operations (`ushr`, `and`) when building formatted hex output, which avoids intermediate string creation entirely. Ensure 100% branch coverage with test inputs spanning both < 10 and > 9 hex values.
## $(date +%Y-%m-%d) - [불필요한 정렬 제거 및 조기 종료로 파일 무시 로직 최적화]
**Learning:** 최종 결과가 순서가 없는 Set에 저장될 때, 입력 데이터를 정렬(.sorted())하는 것은 불필요한 O(N log N) 비용을 발생시킵니다. 또한 여러 정규식 패턴을 순회할 때 조건을 만족하면 즉시 종료(.any())하여 최악의 경우 O(N*M)가 되는 것을 방지할 수 있습니다.
**Action:** Set과 같이 순서를 보장하지 않는 자료구조를 사용할 때는 불필요한 중간 정렬을 피하고, 단순 매칭 여부만 판단할 경우 전체 순회(forEach) 대신 short-circuiting이 가능한 메서드(any, all, first 등)를 활용할 것.
14 changes: 7 additions & 7 deletions src/main/kotlin/html4tree/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ fun process_ignore_file(curr_dir: File): Set<String> {
}
}

curr_dir.list()?.sorted()?.forEach {
val current = it
ignored_regexes.forEach { regex ->
if(regex.matches(current)){
files_to_exclude.add(current)
}
}
// ⚡ Bolt 성능 최적화: 불필요한 정렬을 제거하고 any를 사용하여 조기 종료
// 결과를 Set에 추가하므로 디렉토리 목록을 정렬할 필요가 없습니다.
// `any`를 사용하면 일치 항목을 찾는 즉시 정규식 평가를 중지하여 최악의 경우(O(n*m))를 방지합니다.
curr_dir.list()?.forEach { current ->
if (ignored_regexes.any { regex -> regex.matches(current) }) {
files_to_exclude.add(current)
}
}
}

Expand Down
Loading