⚡ Bolt: [최상위 불변 상수 및 무거운 연산 호이스팅을 통한 디렉토리 순회 최적화]#230
Conversation
반복 호출되는 함수(process_dir) 내부에 있던 상수 HTML/CSS 템플릿과 SHA-256 해시 연산을 최상위 private val로 호이스팅했습니다.
|
👋 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 optimizes html4tree’s directory traversal by hoisting invariant/static HTML/CSS strings and an expensive SHA-256 computation out of hot-path functions (process_dir, process_ignore_file) into top-level private vals, reducing repeated allocations and CPU work during large crawls.
Changes:
- Hoisted the default sensitive-file exclusion list into a top-level
private val. - Hoisted CSS template strings and the CSP SHA-256 style hash calculation into top-level
private vals. - Documented the optimization approach in
.jules/bolt.md.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/main/kotlin/html4tree/main.kt | Hoists static CSS/HTML fragments and SHA-256 CSP hash computation out of frequently called functions. |
| .jules/bolt.md | Adds a dated entry documenting the hoisting optimization lesson/action. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| """ | ||
|
|
||
| private val styleHash = "sha256-" + Base64.getEncoder().encodeToString(MessageDigest.getInstance("SHA-256").digest(cssContent.toByteArray(Charsets.UTF_8))) | ||
|
|
||
| private val css = """ | ||
| <style> | ||
| ${cssContent} </style> | ||
| """ |
💡 What:
디렉토리 크롤링 시 반복 호출되는
process_dir및process_ignore_file함수 내부에 하드코딩되어 매번 생성되던 정적 문자열(CSS, HTML 템플릿 일부, 민감 파일 목록)과 비싼 연산인 SHA-256 해시 계산을 최상위private val상수로 호이스팅(hoisting)했습니다.🎯 Why:
Kotlin에서 함수 내부에 선언된 변수나 연산은 함수가 호출될 때마다 반복적으로 평가되고 할당됩니다. 특히 크롤러와 같이
process_dir이 수많은 디렉토리에 대해 재귀적으로 호출되는 상황에서, 동일한 정적 문자열의 반복적 인스턴스화와 SHA-256 해시 재계산은 상당한 CPU 오버헤드와 가비지 컬렉션(GC) 압력을 유발하여 성능 저하의 주요 원인이 됩니다.📊 Impact:
process_dir호출 시마다 발생하던 불필요한 메모리 할당(String, List)을 제거하여 GC 압력 감소🔬 Measurement:
./gradlew clean test jacocoTestReport jacocoTestCoverageVerification).private val선언으로 컴파일러가 자동 생성하는 public getter로 인한 불필요한 메서드 노출을 방지했습니다.PR created automatically by Jules for task 16008309609710336152 started by @seonghobae