⚡ Bolt: Use path.read_bytes() over path.read_text() for json.loads() - #445
⚡ Bolt: Use path.read_bytes() over path.read_text() for json.loads()#445seonghobae wants to merge 4 commits into
Conversation
- json.loads() 호출 시 read_text() 대신 read_bytes()를 사용하여 문자열 할당 및 디코딩 오버헤드 감소 - 관련된 mock 테스트 수정 - 최적화 내용 .jules/bolt.md에 기록
|
👋 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. |
|
Warning Review limit reached
Next review available in: 18 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates JSON file loading in the NewsDOM API codebase to pass raw bytes into json.loads() (via Path.read_bytes()) instead of decoding to an intermediate UTF-8 string first, aligning with the repo’s “⚡ Bolt” performance notes.
Changes:
- Switch
_read_mineru_json()(MinerU artifact parsing) tojson.loads(path.read_bytes()). - Switch
equivalence.load_metrics()tojson.loads(path.read_bytes()). - Update MinerU runner path tests to monkeypatch
Path.read_bytes()instead ofPath.read_text(); remove an obsoletepatch.diffartifact and record the Bolt learning.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/newsdom_api/mineru_runner.py |
Reads MinerU JSON artifacts via read_bytes() before json.loads() to avoid intermediate decoded-string allocation. |
src/newsdom_api/equivalence.py |
Loads metrics JSON via read_bytes() before json.loads() for the same allocation avoidance pattern. |
tests/test_mineru_runner_paths.py |
Updates monkeypatching to intercept read_bytes() so read-failure differentiation tests remain valid. |
patch.diff |
Removes a no-longer-needed patch artifact file from the repo. |
.jules/bolt.md |
Adds a Bolt note capturing the rationale and preferred pattern for json.loads() inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Upgraded dependencies to address Trivy filesystem scan vulnerabilities.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
tests/test_mineru_runner_paths.py:621
- Same issue here:
read_bytes()cannot raiseUnicodeDecodeErrorbecause it doesn't decode. If you want to cover the Unicode decode failure path, return invalid bytes for that case so the error originates fromjson.loads(...).
def fake_read_bytes(self, *args, **kwargs):
if self.name == file_name:
raise read_error
return original_read_bytes(self, *args, **kwargs)
| @@ -10,7 +10,8 @@ | |||
| def load_metrics(path: Path) -> dict[str, Any]: | |||
| """Load a JSON metrics file from disk using UTF-8 encoding.""" | |||
| def fake_read_bytes(self, *args, **kwargs): | ||
| if self.name == file_name: | ||
| raise read_error | ||
| return original_read_text(self, *args, **kwargs) | ||
| return original_read_bytes(self, *args, **kwargs) |
Upgraded dependencies to address Trivy filesystem scan vulnerabilities.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
tests/test_mineru_runner_paths.py:294
- The UnicodeDecodeError case is currently simulated by raising UnicodeDecodeError from Path.read_bytes(), but read_bytes() won’t raise that in real usage; the decode error would come from json.loads(...) when it decodes invalid UTF-8 bytes. Adjusting the fake to return invalid bytes makes the test reflect the real failure mode and avoids brittleness if the implementation changes where decoding happens.
def fake_read_bytes(self, *args, **kwargs):
if self.name == file_name:
raise read_error
return original_read_bytes(self, *args, **kwargs)
tests/test_mineru_runner_paths.py:621
- Same issue as above: simulating UnicodeDecodeError by raising it from Path.read_bytes() is not representative (decoding happens inside json.loads for bytes input). Returning invalid bytes for the UnicodeDecodeError test case better matches the real behavior and prevents false failures if decoding is refactored.
def fake_read_bytes(self, *args, **kwargs):
if self.name == file_name:
raise read_error
return original_read_bytes(self, *args, **kwargs)
| "Pillow>=11.0,<13.0", | ||
| "pypdf>=6.13.3,<7.0", | ||
| "pymdown-extensions>=10.21.3", | ||
| ] |
Upgraded dependencies to address Trivy filesystem scan vulnerabilities.
💡 What:
json.loads의 입력으로path.read_text(encoding="utf-8")대신path.read_bytes()를 사용하도록 변경했습니다.🎯 Why:
read_text를 사용하면 Python이 메모리에 디코딩된 문자열을 미리 할당해야 하지만,read_bytes를 통해 바이트를 직접 전달하면 C 구현체인 JSON 파서가 이를 직접 디코딩하므로 더 효율적입니다.📊 Impact: 중간 문자열 할당 방지를 통한 메모리 효율 증가 및 미세 속도 향상.
🔬 Measurement: unit test 및 type checker 통과 여부 확인 (테스트 내
read_textmock을read_bytesmock으로 정상 갱신 확인 완료).PR created automatically by Jules for task 3674714420964721809 started by @seonghobae