-
Notifications
You must be signed in to change notification settings - Fork 16
Perf: Replace slow pixel-by-pixel color loop with Image.composite #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Perf: Replace slow pixel-by-pixel color loop with Image.composite #391
Conversation
The PillowResult.get_image method used a slow, pure-Python loop to apply styles, causing significant performance degradation on large images. This commit replaces that implementation with a single, highly-optimized call to Image.composite, using the rendered B&W image as a mask. This reduces rendering time by over 90% in test cases.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #391 +/- ##
==========================================
- Coverage 86.25% 86.25% -0.01%
==========================================
Files 165 165
Lines 7831 7821 -10
==========================================
- Hits 6755 6746 -9
+ Misses 1076 1075 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Hi, thank you for your PR. I will try to find time to review and benchmark this soon. |
Please fix all the code style issues reported by ruff. For a quick guide on how to set up a local dev environment please check out Development documentation. At the moment only style issues reported is a formatting issue which can be auto-fixed with a single command:
|
Thanks for the pointers! I’ve set up the local dev env per the docs and ran:
This applied the ruff-format changes that CI flagged. I’ve committed and pushed those fixes, so the Style check should pass now. The PR is ready for your review/benchmarking. I’m happy to tweak anything further (naming, comments, tests, etc.) if you prefer a different approach. |
The PillowResult.get_image method used a slow, pure-Python loop to apply styles, causing significant performance degradation on large images. This commit replaces that implementation with a single, highly-optimized call to Image.composite, using the rendered B&W image as a mask. This reduces rendering time by over 90% in test cases.