⚡ Bolt: [성능 개선] process_dir 내 정적 문자열 및 해시 계산 추출#243
Conversation
- `process_dir` 루프 안에서 매번 생성되던 큰 CSS 문자열과 SHA-256 연산을 상단 `private object Constants`로 분리 - 디렉토리 내의 파일 수가 많아질 때 메모리 할당 및 가비지 컬렉션(GC) 압박을 크게 감소시킴 - `const val`과 `@JvmField`를 활용하여 Kotlin 컴파일러에 의한 암시적 Getter 생성을 억제하고 성능 최적화 및 100% 테스트 커버리지 유지
|
👋 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 refactors process_dir to avoid re-allocating large static HTML/CSS strings and re-computing the CSS SHA-256 hash on every directory render, by moving them to a file-level private object Constants in main.kt.
Changes:
- Extracted the large CSS/HTML footer strings and the
styleHashcalculation intoConstantsto cache them across calls. - Updated CSP meta tag and HTML template assembly to reference
Constants.styleHash,Constants.css, andConstants.index_bottom. - Added a new performance-learning entry documenting the optimization 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/footer strings and the CSP style hash computation out of process_dir to reduce repeated allocations and hashing. |
| .jules/bolt.md | Documents the performance optimization as a new “learning/action” entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const val css = """ | ||
| <style> | ||
| ${cssContent} </style> | ||
| """ |
💡 What:
html4tree/main.kt의process_dir함수 내부에 정의되어 있던 크기가 큰 CSS 문자열(cssContent,css,index_bottom)과 정적 리소스 해시(styleHash) 계산 로직을 파일 레벨의private object Constants로 추출했습니다.🎯 Why:
기존 코드에서는 디렉토리를 순회할 때마다 매번 큰 크기의 문자열 인스턴스를 메모리에 할당하고 무거운 연산(SHA-256)을 반복 수행하고 있었습니다. 이를 정적 공간으로 분리함으로써 불필요한 반복 메모리 할당(GC 오버헤드) 및 CPU 연산을 방지하여 렌더링 성능을 개선합니다. 특히 디렉토리 깊이나 파일 갯수가 많아질수록 성능 차이가 극명하게 발생합니다.
📊 Impact:
process_dir이 호출될 때 발생하는 정적 리소스에 대한 문자열 재할당 및 해시 연산 비용이 100% 제거되었습니다.🔬 Measurement:
./gradlew clean test jacocoTestReport jacocoTestCoverageVerification를 실행하여 기능이 동일하게 유지되며, 100% 테스트 커버리지를 만족하는지 확인했습니다.object특성을 회피하기 위해const val과@JvmField어노테이션이 사용된 것을 확인 가능합니다.PR created automatically by Jules for task 11908346449558853911 started by @seonghobae