Skip to content

Add optional parallel compression steps#18

Merged
rohan-patnaik merged 1 commit intomainfrom
codex/compress-parallelism
Feb 3, 2026
Merged

Add optional parallel compression steps#18
rohan-patnaik merged 1 commit intomainfrom
codex/compress-parallelism

Conversation

@rohan-patnaik
Copy link
Copy Markdown
Owner

@rohan-patnaik rohan-patnaik commented Feb 3, 2026

Summary

  • add optional parallel execution for compression heavy steps via ZENPDF_COMPRESS_PARALLELISM
  • keep default single-threaded behavior while allowing faster wall-clock when enabled
  • document new setting in tool techniques and env example

Testing

  • Not run (not requested)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

This pull request introduces parallel execution capabilities for PDF optimization steps in the worker. A new environment variable ZENPDF_COMPRESS_PARALLELISM controls concurrent task execution. The main worker code refactors optimization workflows into modular task functions that execute concurrently when parallelism > 1, with sequential execution as the default behavior.

Changes

Cohort / File(s) Summary
Configuration & Documentation
apps/worker/.env.example, docs/TOOL_TECHNIQUES.md
Added ZENPDF_COMPRESS_PARALLELISM environment variable with default value of 1, and documented its purpose as controlling optional concurrent execution of heavy optimization steps.
Core Optimization Logic
apps/worker/zenpdf_worker/tools.py
Refactored PDF optimization workflow to support parallel execution using ThreadPoolExecutor; extracted step recording into _make_step_entry function; modularized image optimization, pdfsizeopt, and ghostscript workflows into dedicated task functions returning structured outcomes; added conditional orchestration to run tasks concurrently when parallelism > 1; consolidated temporary file tracking across parallel tasks; expanded ghostscript workflow with probe, full run, and conditional retry phases.

Sequence Diagram(s)

sequenceDiagram
    participant Coord as Orchestrator
    participant ImgOpt as Image<br/>Optimization
    participant PdfOpt as pdfsizeopt<br/>Task
    participant GS as Ghostscript<br/>Task
    participant TempMgr as Temp File<br/>Manager

    rect rgba(100, 150, 200, 0.5)
    Note over Coord: Parallelism > 1 Flow
    Coord->>Coord: Evaluate task thresholds
    par Concurrent Execution
        Coord->>ImgOpt: Execute async
        ImgOpt->>ImgOpt: Optimize images
        ImgOpt-->>Coord: Return (steps, temps, candidates)
    and
        Coord->>PdfOpt: Execute async
        PdfOpt->>PdfOpt: Run pdfsizeopt
        PdfOpt-->>Coord: Return (steps, temps, candidates)
    and
        Coord->>GS: Execute async
        GS->>GS: Probe + Full run + Retry
        GS-->>Coord: Return (steps, temps, candidates)
    end
    end

    rect rgba(150, 200, 100, 0.5)
    Note over Coord: Post-Execution
    Coord->>Coord: Aggregate results<br/>from all tasks
    Coord->>TempMgr: Collect & deduplicate<br/>temp files
    TempMgr->>TempMgr: Remove artifacts
    Coord-->>Coord: Return optimized PDF
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 Hopping through code with parallel grace,
Threads now dance at a faster pace,
Image and PDF tasks intertwine,
Optimization steps compress just fine,
Faster PDFs hop off to the race! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add optional parallel compression steps' directly and accurately summarizes the main change: introducing optional parallelization for compression operations via the ZENPDF_COMPRESS_PARALLELISM environment variable.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/compress-parallelism

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@rohan-patnaik
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 3, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@rohan-patnaik rohan-patnaik merged commit 50f833b into main Feb 3, 2026
4 checks passed
@rohan-patnaik rohan-patnaik deleted the codex/compress-parallelism branch February 23, 2026 14:05
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