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 @@ -5,3 +5,6 @@
## 2024-05-24 - Loop Allocation Hot Paths
**Learning:** Rendering directory entries with repeated string concatenation and list-based exclusion lookups creates avoidable allocation and lookup cost in large directories.
**Action:** Use `StringBuilder` for entry rendering and a `Set` for excluded file names.
## 2024-07-04 - Optimize `process_ignore_file` performance
**Learning:** In operations dealing with file exclusions and regex matching, unnecessarily sorting the file list introduces an O(N log N) penalty. Evaluating all exclusion regexes even after a match occurs incurs an O(N * M) penalty, especially noticeable with many files or complex regexes.
**Action:** Avoid sorting operations when only checking for existence or matching within a set. Always use early exits (`break`) in loops once a condition is successfully met to prevent redundant checks.
11 changes: 6 additions & 5 deletions src/main/kotlin/html4tree/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fun main(args: Array<String>) = Html4tree().main(args)

fun go(topDir: String, maxLevel: Int) {
require(topDir.isNotBlank())
val top_dir = File(topDir).canonicalFile
val top_dir = File(topDir).absoluteFile
require(Files.isDirectory(top_dir.toPath(), LinkOption.NOFOLLOW_LINKS)) { "Top directory must be an existing non-symlink directory" }

val ll = LinkedList()
Expand Down Expand Up @@ -101,13 +101,14 @@ fun process_ignore_file(curr_dir: File): Set<String> {
}
}

curr_dir.list()?.sorted()?.forEach {
val current = it
ignored_regexes.forEach { regex ->
// ⚡ Bolt: 성능 최적화 - 불필요한 O(N log N) 정렬 제거 및 조기 반환(break)을 통한 중복 정규식 검사 방지
curr_dir.list()?.forEach { current ->
for (regex in ignored_regexes) {
if(regex.matches(current)){
files_to_exclude.add(current)
break
}
}
}
}
}

Expand Down
Loading