⚡ Bolt: [performance improvement] Hoist static strings and expensive SHA-256 out of loop#256
⚡ Bolt: [performance improvement] Hoist static strings and expensive SHA-256 out of loop#256seonghobae wants to merge 1 commit into
Conversation
…SHA-256 out of loop 💡 What: `process_dir` 내부에 위치하던 불변 정적 문자열(`cssContent`, `css`)과 비용이 큰 SHA-256 해시 연산 코드를 최상위 레벨의 `private val` 상수로 호이스팅했습니다. 🎯 Why: 해당 변수들은 파일 디렉토리 크롤링 시 `process_dir` 호출마다 변하지 않는 고정된 값입니다. 그럼에도 불구하고 매번 호출될 때마다 무거운 SHA-256 연산과 대량의 문자열 할당이 반복적으로 발생하여 불필요한 메모리(GC) 및 CPU 오버헤드를 유발하고 있었습니다. 📊 Impact: 디렉토리를 순회할 때마다 발생하던 중복된 메모리 할당 및 해시 연산 비용이 사라졌습니다. 특히 많은 디렉토리(1,000개 이상)를 순회할 때 처리 속도가 개선되며 메모리 압박이 대폭 줄어듭니다. 🔬 Measurement: 테스트 커버리지 100%를 유지하는지 확인하기 위해 `./gradlew clean test jacocoTestReport jacocoTestCoverageVerification --continue`를 실행하여 통과함을 확인했습니다.
|
👋 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 improves html4tree’s directory indexing performance by hoisting per-directory invariant CSS strings and the SHA-256 CSP hash computation out of process_dir into top-level private vals, reducing repeated allocations and hashing work during large crawls.
Changes:
- Hoisted
cssContent,css, andstyleHashfrom insideprocess_dirto top-levelprivate vals to avoid repeated string allocation and SHA-256 hashing per directory. - Added a new Bolt learning entry documenting the optimization rationale and intended impact.
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 and CSP hash computation out of process_dir to reduce repeated work during directory traversal. |
| .jules/bolt.md | Documents the performance optimization as a new Bolt learning/action entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private val css = """ | ||
| <style> | ||
| ${cssContent} </style> | ||
| """ |
💡 What:
process_dir내부에 위치하던 불변 정적 문자열(cssContent,css)과 비용이 큰 SHA-256 해시 연산 코드를 최상위 레벨의private val상수로 호이스팅했습니다.🎯 Why:
해당 변수들은 파일 디렉토리 크롤링 시
process_dir호출마다 변하지 않는 고정된 값입니다. 그럼에도 불구하고 매번 호출될 때마다 무거운 SHA-256 연산과 대량의 문자열 할당이 반복적으로 발생하여 불필요한 메모리(GC) 및 CPU 오버헤드를 유발하고 있었습니다.📊 Impact:
디렉토리를 순회할 때마다 발생하던 중복된 메모리 할당 및 해시 연산 비용이 사라졌습니다. 특히 많은 디렉토리(1,000개 이상)를 순회할 때 처리 속도가 개선되며 메모리 압박이 대폭 줄어듭니다.
🔬 Measurement:
테스트 커버리지 100%를 유지하는지 확인하기 위해
./gradlew clean test jacocoTestReport jacocoTestCoverageVerification --continue를 실행하여 통과함을 확인했습니다.PR created automatically by Jules for task 11568844940393443262 started by @seonghobae