Skip to content

⚡ Bolt: [Optimize yEnc Decoding]#10

Open
xbmc4lyfe wants to merge 1 commit into
mainfrom
bolt/yenc-decode-optimization-1416107150303298838
Open

⚡ Bolt: [Optimize yEnc Decoding]#10
xbmc4lyfe wants to merge 1 commit into
mainfrom
bolt/yenc-decode-optimization-1416107150303298838

Conversation

@xbmc4lyfe
Copy link
Copy Markdown
Collaborator

💡 What:
Replaced the Python while loop that iterates over each byte in a yEnc payload with bytes.split(b"="). Mapped unmodified bytes using a precomputed _YENC_DECODE_TABLE via bytes.translate(), and combined math logic for escaped bytes.

🎯 Why:
Iterating over byte sequences manually in Python creates huge overhead because each operation runs at bytecode speed rather than C speed. By shifting string operations to native C-methods (translate and split), the runtime is significantly reduced.

📊 Impact:
Decoding time drops from ~0.70 seconds to ~0.08 seconds (nearly a 10x improvement).

🔬 Measurement:
Running benchmarking on dummy yEnc data with lengths around 50,000 bytes confirms the ~10x speedup. Passed python3 -m unittest discover tests.


PR created automatically by Jules for task 1416107150303298838 started by @xbmc4lyfe

Replaced per-byte iteration loop in `_decode_yenc_lines` with C-level optimizations.

💡 What:
Replaced the Python `while` loop that iterates over each byte in a yEnc payload with `bytes.split(b"=")`. Mapped unmodified bytes using a precomputed `_YENC_DECODE_TABLE` via `bytes.translate()`, and combined math logic for escaped bytes.

🎯 Why:
Iterating over byte sequences manually in Python creates huge overhead because each operation runs at bytecode speed rather than C speed. By shifting string operations to native C-methods (`translate` and `split`), the runtime is significantly reduced.

📊 Impact:
Decoding time drops from ~0.70 seconds to ~0.08 seconds (nearly a 10x improvement).

🔬 Measurement:
Running benchmarking on dummy yEnc data with lengths around 50,000 bytes confirms the ~10x speedup. Passed `python3 -m unittest discover tests`.

Co-authored-by: xbmc4lyfe <273732874+xbmc4lyfe@users.noreply.github.com>
@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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 03f67cb1-6086-43a6-a6b6-fb600ba20c0b

📥 Commits

Reviewing files that changed from the base of the PR and between 09ccc06 and 016615b.

📒 Files selected for processing (1)
  • verify_nzb.py
📜 Recent review details
🔇 Additional comments (1)
verify_nzb.py (1)

118-119: LGTM!

Also applies to: 122-137


📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Optimized NZB file decoding for improved processing speed.

Walkthrough

This PR optimizes yEnc body decoding in verify_nzb.py by replacing a byte-by-byte decoder with a faster implementation using a precomputed 256-byte translation table and Python's built-in bytes.translate() method. The new decoder processes unescaped bytes in bulk and handles escaped sequences with simplified arithmetic.

Changes

yEnc Decoding Optimization

Layer / File(s) Summary
Optimized yEnc decoder implementation
verify_nzb.py
Module-level yEnc translation table (256 bytes) and rewritten _decode_yenc_lines() function. The function now splits each input line on the yEnc escape marker (=), applies bulk byte translation to unescaped segments, and uses direct arithmetic to decode escaped sequences. Removes the previous character-by-character looping decoder.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A faster decoder hops along,
With tables precomputed strong,
No byte-by-byte, just bulk translate,
Escape-marked splits make data fate,
Performance springs from clever thought! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change as yEnc decoding optimization, which aligns with the core objective of replacing the decoding routine with a faster implementation.
Description check ✅ Passed The description is directly related to the changeset, providing clear context about the optimization approach, motivation, measured impact, and testing performed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt/yenc-decode-optimization-1416107150303298838
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch bolt/yenc-decode-optimization-1416107150303298838

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

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.

1 participant