Skip to content

⚡ Bolt: Use path.read_bytes() over path.read_text() for json.loads() - #445

Open
seonghobae wants to merge 4 commits into
developfrom
bolt-json-loads-read-bytes-3674714420964721809
Open

⚡ Bolt: Use path.read_bytes() over path.read_text() for json.loads()#445
seonghobae wants to merge 4 commits into
developfrom
bolt-json-loads-read-bytes-3674714420964721809

Conversation

@seonghobae

Copy link
Copy Markdown
Collaborator

💡 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_text mock을 read_bytes mock으로 정상 갱신 확인 완료).


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

- json.loads() 호출 시 read_text() 대신 read_bytes()를 사용하여 문자열 할당 및 디코딩 오버헤드 감소
- 관련된 mock 테스트 수정
- 최적화 내용 .jules/bolt.md에 기록
@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 review requested due to automatic review settings July 27, 2026 21:53
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@seonghobae, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fc08ca9a-a8fa-4c99-afc6-cf8778cc8378

📥 Commits

Reviewing files that changed from the base of the PR and between 04491c0 and 63103e6.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • .jules/bolt.md
  • patch.diff
  • pyproject.toml
  • src/newsdom_api/equivalence.py
  • src/newsdom_api/mineru_runner.py
  • tests/test_mineru_runner_paths.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-json-loads-read-bytes-3674714420964721809

Comment @coderabbitai help to get the list of available commands.

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 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) to json.loads(path.read_bytes()).
  • Switch equivalence.load_metrics() to json.loads(path.read_bytes()).
  • Update MinerU runner path tests to monkeypatch Path.read_bytes() instead of Path.read_text(); remove an obsolete patch.diff artifact 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.
Copilot AI review requested due to automatic review settings July 27, 2026 21:56

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

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 raise UnicodeDecodeError because it doesn't decode. If you want to cover the Unicode decode failure path, return invalid bytes for that case so the error originates from json.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."""
Comment on lines +291 to +294
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.
Copilot AI review requested due to automatic review settings July 27, 2026 22:05

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

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)

Comment thread pyproject.toml
Comment on lines 19 to 22
"Pillow>=11.0,<13.0",
"pypdf>=6.13.3,<7.0",
"pymdown-extensions>=10.21.3",
]
Upgraded dependencies to address Trivy filesystem scan vulnerabilities.
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