Skip to content

⚡ Bolt: [성능 최적화] O(n^2) 디렉토리 처리 및 문자열 연결 병목 현상 제거 - #40

Closed
seonghobae wants to merge 3 commits into
masterfrom
bolt/performance-optimizations-4159131252985411441
Closed

⚡ Bolt: [성능 최적화] O(n^2) 디렉토리 처리 및 문자열 연결 병목 현상 제거#40
seonghobae wants to merge 3 commits into
masterfrom
bolt/performance-optimizations-4159131252985411441

Conversation

@seonghobae

Copy link
Copy Markdown
Collaborator

💡 What:

  • process_ignore_file가 반환하는 파일 제외 목록의 데이터 구조를 List에서 Set으로 변경했습니다.
  • 디렉토리 파일을 루프할 때 발생하는 문자열의 반복적인 결합(+=) 대신 StringBuilder를 도입했습니다.
  • 성능 최적화의 의도를 명확하게 보여주는 인라인 주석을 코드에 추가했습니다.
  • 코드베이스의 동작을 증명하는 JUnit 단위 테스트를 추가하고 Jacoco를 이용한 100% 테스트 커버리지를 구현했습니다.

🎯 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 jacocoTestCoverageVerification


PR created automatically by Jules for task 4159131252985411441 started by @seonghobae

- `process_ignore_file`가 List 대신 Set을 반환하도록 변경하여 O(n) 조회에서 O(1)로 단축
- `index_middle` 루프에서 문자열 연결 (`+=`) 대신 `StringBuilder`를 사용하여 메모리 할당 병목 제거
- 불필요한 `.sorted()` 호출을 제거
- 100% 테스트 커버리지 및 Jacoco 설정 추가
Copilot AI review requested due to automatic review settings June 28, 2026 03:44
@google-labs-jules

Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Set for faster membership checks.
  • Replaced looped string concatenation with StringBuilder when 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 .forEach on 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.

Comment thread src/main/kotlin/html4tree/main.kt Outdated
Comment thread src/test/kotlin/html4tree/MainTest.kt Outdated
Comment thread src/test/kotlin/html4tree/LinkedListTest.kt Outdated
@seonghobae

Copy link
Copy Markdown
Collaborator Author

Closing as superseded by already-merged performance fixes (#20/#21). Current master already uses a Set for ignore exclusions and StringBuilder for generated listing rows, while also preserving newer safe URL encoding, invalid-regex handling, symlink protections, and accessibility output.

@seonghobae seonghobae closed this Jun 30, 2026
@google-labs-jules

Copy link
Copy Markdown

Closing as superseded by already-merged performance fixes (#20/#21). Current master already uses a Set for ignore exclusions and StringBuilder for generated listing rows, while also preserving newer safe URL encoding, invalid-regex handling, symlink protections, and accessibility output.

Understood. Acknowledging that this work is superseded by already-merged PRs and stopping work on this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants