Skip to content

[Refactor:Autograding] Optimize PDF speed#12471

Merged
bmcutler merged 14 commits into
Submitty:mainfrom
GarvitKhandelwal31:perf-investigation-vm-size
Jun 3, 2026
Merged

[Refactor:Autograding] Optimize PDF speed#12471
bmcutler merged 14 commits into
Submitty:mainfrom
GarvitKhandelwal31:perf-investigation-vm-size

Conversation

@GarvitKhandelwal31

@GarvitKhandelwal31 GarvitKhandelwal31 commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

Why is this Change Important & Necessary?
Fixes #11867. When testing PR #11539 (PDF Redactions), performance issues were found in PDF image generation with redactions enabled. This PR improves performance by switching the rendering backend and adds safety fixes for concurrent bulk regeneration and caching.

What is the New Behavior?
1)PyMuPDF Integration: Replaced the previous PDF rendering approach with PyMuPDF (fitz) for faster page rendering.
2) Caching with Redaction Awareness: Adds a cache keyed on the PDF contents and redaction data, so changing redactions correctly forces regeneration.
3) Daemon support updates.

What steps should a reviewer take to reproduce or test the new feature?

  1. Test it on a gradeable with pdf redactions enabled. I tested on this gradeable Bulk Upload Scanned Exam.
  2. Upload the json redactions file
    You can use this-
    [
    {
    "page": 1,
    "x1": 0.25,
    "y1": 0.25,
    "x2": 0.75,
    "y2": 0.75
    },
    {
    "page": 2,
    "x1": 0.1,
    "y1": 0.1,
    "x2": 0.9,
    "y2": 0.9
    }
    ]
  3. I have tested on a 28 page pdf file.
  4. Watch the daemon logs (sudo journalctl -u submitty_daemon_jobs_handler.service -f)
  5. Performance on my system-
    On main it took around 10 seconds
    On the PR's branch it took around 5.27 second
Screenshot 2026-06-03 143240 6. Modify redactions and regenerate again, images should update (cache invalidated).

Automated Testing & Documentation
No new tests were added.
Other information

- Replace pdf2image with PyMuPDF for faster PDF processing
- Add pattern caching for instant redaction rendering
- Implement parallel processing for bulk operations (1.7x speedup)
- Add file caching to skip unchanged submissions
- Optimize memory usage (70% reduction)
- Remove external poppler dependency

Resolves performance concerns from PR Submitty#11539
@github-project-automation github-project-automation Bot moved this to Seeking Reviewer in Submitty Development Feb 23, 2026
@GarvitKhandelwal31 GarvitKhandelwal31 changed the title [Performance] Optimize PDF redaction processing speed using PyMuPDF [Performance] Optimize PDF redactions Feb 23, 2026
@GarvitKhandelwal31 GarvitKhandelwal31 changed the title [Performance] Optimize PDF redactions [Refactor:Autograding] Optimize PDF speed Feb 23, 2026
@automateprojectmangement automateprojectmangement Bot moved this from Seeking Reviewer to In Review in Submitty Development Feb 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 optimizes PDF image generation performance by replacing pdf2image and PyPDF2 with PyMuPDF (fitz), achieving 20-30x speedup. It addresses performance bottlenecks discovered during testing of the PDF redactions feature (#11539), eliminating the need to scale up VM hardware.

Changes:

  • Migrated generate_pdf_images.py to use PyMuPDF for PDF rendering with optimized redaction pattern caching
  • Added parallel processing to regenerate_bulk_images.py using ThreadPoolExecutor with configurable worker counts
  • Extended jobs.py to support configurable max_workers parameter for the regenerate bulk images job

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.

File Description
sbin/submitty_daemon_jobs/submitty_jobs/generate_pdf_images.py Replaced pdf2image/PyPDF2 with PyMuPDF, added file hash caching, optimized redaction pattern generation
sbin/submitty_daemon_jobs/submitty_jobs/regenerate_bulk_images.py Added parallel processing with ThreadPoolExecutor, statistics tracking, and error handling for bulk image regeneration
sbin/submitty_daemon_jobs/submitty_jobs/jobs.py Added max_workers parameter support for configurable parallelism

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sbin/submitty_daemon_jobs/submitty_jobs/regenerate_bulk_images.py Outdated
Comment thread sbin/submitty_daemon_jobs/submitty_jobs/regenerate_bulk_images.py Outdated
Comment thread sbin/submitty_daemon_jobs/submitty_jobs/generate_pdf_images.py Outdated
Comment thread sbin/submitty_daemon_jobs/submitty_jobs/generate_pdf_images.py Outdated
Comment thread sbin/submitty_daemon_jobs/submitty_jobs/generate_pdf_images.py
Comment thread sbin/submitty_daemon_jobs/submitty_jobs/generate_pdf_images.py Outdated
Comment thread sbin/submitty_daemon_jobs/submitty_jobs/regenerate_bulk_images.py Outdated
Comment thread sbin/submitty_daemon_jobs/submitty_jobs/regenerate_bulk_images.py Outdated
Comment thread sbin/submitty_daemon_jobs/submitty_jobs/generate_pdf_images.py Outdated
Comment thread sbin/submitty_daemon_jobs/submitty_jobs/generate_pdf_images.py Outdated
@codecov

codecov Bot commented Feb 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 21.64%. Comparing base (cf41dbd) to head (6775fab).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##               main   #12471   +/-   ##
=========================================
  Coverage     21.64%   21.64%           
  Complexity     9818     9818           
=========================================
  Files           268      268           
  Lines         36777    36777           
  Branches        490      490           
=========================================
  Hits           7960     7960           
  Misses        28331    28331           
  Partials        486      486           
Flag Coverage Δ
autograder 21.32% <ø> (ø)
js 2.02% <ø> (ø)
migrator 100.00% <ø> (ø)
php 20.69% <ø> (ø)
python_submitty_utils 80.08% <ø> (ø)
submitty_daemon_jobs 91.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GarvitKhandelwal31

Copy link
Copy Markdown
Contributor Author

@williamjallen I have fixed the Python Linting issues and also taken copilot suggestions. Can you please rerun workflows to see , if any errors still remains?

Thanks

@JManion32

Copy link
Copy Markdown
Contributor

@GarvitKhandelwal31 Please address the failing CI tests. This is a big change that looks like it may affect a sizeable part of CI, so there may be more refactoring necessary before this can be reviewed.

@GarvitKhandelwal31

Copy link
Copy Markdown
Contributor Author

@williamjallen I believe the failing one Cypress workflow in previous commit is due to an existing issue, and not related to my changes.

@GarvitKhandelwal31

Copy link
Copy Markdown
Contributor Author

I think the failing Cypress(UI) is due to an existing issue and not related to any of the files I have changed.

Can a maintainer please guide me on this?

@github-actions github-actions Bot added the Abandoned PR - Needs New Owner No activity on PR for more than 2 weeks -- seeking new owner to complete label Apr 3, 2026
@GarvitKhandelwal31 GarvitKhandelwal31 removed the Abandoned PR - Needs New Owner No activity on PR for more than 2 weeks -- seeking new owner to complete label May 19, 2026
@mattLif
mattLif self-requested a review June 1, 2026 17:32

@mattLif mattLif left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with a large PDF both with and without redactions, and works as expected. Redactions successfully generate at a noticeably better speed compared to before the changes. Code looks good too. Just unsure about how Justin feels about the CI tests that are failing, but the changes are successful.

@github-project-automation github-project-automation Bot moved this from In Review to Awaiting Maintainer Review in Submitty Development Jun 2, 2026
@bmcutler
bmcutler merged commit a42ecbf into Submitty:main Jun 3, 2026
24 of 27 checks passed
@github-project-automation github-project-automation Bot moved this from Awaiting Maintainer Review to Done in Submitty Development Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Bulk upload redactions speed concerns

5 participants