Skip to content

⚡ Bolt: 무거운 작업을 최상위 프로퍼티로 추출하여 최적화#238

Open
seonghobae wants to merge 1 commit into
masterfrom
bolt-optimize-process-dir-14016814695631568917
Open

⚡ Bolt: 무거운 작업을 최상위 프로퍼티로 추출하여 최적화#238
seonghobae wants to merge 1 commit into
masterfrom
bolt-optimize-process-dir-14016814695631568917

Conversation

@seonghobae

Copy link
Copy Markdown
Collaborator

💡 What: process_dir 내에서 매번 계산되던 cssContent, styleHash(SHA-256 해시), css 변수를 파일 최상위(top-level) 프로퍼티로 분리했습니다.
🎯 Why: html4tree는 디렉토리를 순회할 때마다 재귀적으로 process_dir 함수를 호출합니다. 그 안에 위치하던 SHA-256 해싱 연산과 큰 문자열 선언들이 순회하는 디렉토리 개수만큼 불필요하게 반복 실행되면서 메모리 할당 및 CPU 낭비를 일으키는 병목 현상이 발생했습니다.
📊 Impact: 디렉토리 순회 시 발생하는 불필요한 해시 연산(O(N)) 및 객체 생성을 1회(O(1))로 줄여 성능 향상을 가져왔습니다. 테스트 커버리지는 추가 테스트(testTopLevelPropertiesCoverage)를 통해 100%를 유지했습니다.
🔬 Measurement: 기존과 동일하게 ./gradlew test jacocoTestReport를 실행하여 모든 테스트를 통과하고 100% 명령어 커버리지를 유지하는지 확인할 수 있습니다.


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

Copilot AI review requested due to automatic review settings July 21, 2026 21:19
@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 optimizes html4tree’s directory indexing hot path by extracting the inline CSS string, its SHA-256 CSP hash, and the <style> block template from process_dir into file top-level properties so they’re computed once rather than per-directory.

Changes:

  • Hoisted cssContent, styleHash, and css out of process_dir into top-level properties in main.kt.
  • Added a test intended to keep coverage for the new top-level properties.
  • Documented the optimization in .jules/bolt.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/main/kotlin/html4tree/main.kt Moves CSS/CSP-hash construction to top-level to avoid repeated hashing and string allocations during traversal.
src/test/kotlin/html4tree/MainTest.kt Adds a new test related to the extracted top-level properties.
.jules/bolt.md Records the optimization as a “Bolt” learning/action item.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

font-style: italic;
}
"""
val cssContent = """
}
"""

val styleHash = "sha256-" + Base64.getEncoder().encodeToString(MessageDigest.getInstance("SHA-256").digest(cssContent.toByteArray(Charsets.UTF_8)))
Comment on lines +311 to +314
val css = """
<style>
${cssContent} </style>
"""
Comment on lines +348 to +353
@Test
fun testTopLevelPropertiesCoverage() {
assertTrue(cssContent.contains("font-family"))
assertTrue(styleHash.startsWith("sha256-"))
assertTrue(css.contains("<style>"))
}
Comment thread .jules/bolt.md
Comment on lines +46 to +48
## 2025-01-25 - 무거운 작업의 파일 최상위 프로퍼티 추출 최적화
**학습:** Kotlin에서 재귀적 파일 시스템 탐색과 같은 반복 작업(`process_dir` 등) 중 정적 문자열 선언(CSS 내용 등)이나 무거운 연산(SHA-256 해싱)을 매번 계산하면 불필요한 비용이 발생합니다.
**조치:** 무거운 작업과 정적 문자열을 함수 내부가 아닌 파일 최상위(top-level) 프로퍼티로 이동시켜 단 한 번만 계산 및 할당되도록 최적화했습니다. 단, 이를 통해 100% 테스트 커버리지를 유지하려면 테스트 코드에서 해당 암시적 getter에 접근해야 합니다.
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.

2 participants