⚡ Bolt: [성능 최적화] O(n^2) 디렉토리 처리 및 문자열 연결 병목 현상 제거 - #40
Conversation
- `process_ignore_file`가 List 대신 Set을 반환하도록 변경하여 O(n) 조회에서 O(1)로 단축 - `index_middle` 루프에서 문자열 연결 (`+=`) 대신 `StringBuilder`를 사용하여 메모리 할당 병목 제거 - 불필요한 `.sorted()` 호출을 제거 - 100% 테스트 커버리지 및 Jacoco 설정 추가
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
This PR focuses on improving performance of directory traversal and HTML index generation by removing O(n²) patterns in ignore lookups and string construction, and adds unit tests plus Jacoco configuration to validate behavior and enforce coverage.
Changes:
- Changed ignore-list handling to use a
Setfor faster membership checks. - Replaced looped string concatenation with
StringBuilderwhen building directory listing HTML. - Added JUnit tests and introduced Jacoco reporting/coverage verification configuration.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/kotlin/html4tree/main.kt | Switches ignore results to Set and uses StringBuilder when rendering directory entries. |
| src/test/kotlin/html4tree/MainTest.kt | Adds tests covering escaping/encoding, ignore processing, directory index generation, CLI behaviors, and help(). |
| src/test/kotlin/html4tree/LinkedListTest.kt | Adds tests for LinkedList/entry data classes and push/pull behavior. |
| build.gradle | Adds Jacoco plugin and coverage report/verification tasks. |
| .jules/bolt.md | Documents the performance learnings motivating the optimization. |
Comments suppressed due to low confidence (1)
src/main/kotlin/html4tree/main.kt:77
File.list()can return null (e.g., unreadable directory / I/O error). Calling.forEachon it can throw at runtime, which would break ignore processing. Treat a null listing as empty.
curr_dir.list().forEach {
val current = it
ignored_regexes.forEach { regex ->
if(regex.matches(current)){
files_to_exclude.add(current)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…internal state mutation in test
Understood. Acknowledging that this work is superseded by already-merged PRs and stopping work on this task. |
💡 What:
process_ignore_file가 반환하는 파일 제외 목록의 데이터 구조를List에서Set으로 변경했습니다.+=) 대신StringBuilder를 도입했습니다.🎯 Why:
디렉토리 목록을 생성할 때마다 하위의 모든 파일들을 순회(
n번)하고, 이 과정 내에서 무시할 파일 목록을 조회하거나 문자열을 덧붙이는 동작을 합니다.List내 요소의 존재 여부를 묻는!in연산은 요소의 개수만큼 확인하므로O(n)의 복잡도를 가지며 전체적으로는O(n^2)의 비용을 발생시킵니다. 마찬가지로, 문자열에+=를 수행하면 매번 새로운 객체를 재할당하므로 역시O(n^2)의 메모리 비용을 발생시키는 심각한 성능 안티패턴이었습니다.📊 Impact:
디렉토리 내 파일 수가 많을수록 제곱 단위로 증가하던 탐색 시간과 메모리 사용량이 O(1) 조회와 단일 메모리 버퍼 (
StringBuilder)를 통해 선형적(Linear)으로 감소하게 됩니다.🔬 Measurement:
다음 Gradle 명령어를 통해 단위 테스트의 통과 여부 및 100% 분기/라인 커버리지를 검증할 수 있습니다.
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 && ./gradlew build jacocoTestReport jacocoTestCoverageVerificationPR created automatically by Jules for task 4159131252985411441 started by @seonghobae