Skip to content

⚡ Bolt: Wrap blocking PIL image operations in asyncio.to_thread#50

Draft
davidjuarezdev wants to merge 1 commit intomainfrom
bolt-async-pil-operations-11033434195393069513
Draft

⚡ Bolt: Wrap blocking PIL image operations in asyncio.to_thread#50
davidjuarezdev wants to merge 1 commit intomainfrom
bolt-async-pil-operations-11033434195393069513

Conversation

@davidjuarezdev
Copy link
Copy Markdown
Owner

💡 What: Wrapped the synchronous downscale_image function calls in await asyncio.to_thread within streamrip/media/artwork.py. This function uses the PIL.Image library for CPU/IO-bound processing (Image.open, image.resize, image.save).
🎯 Why: PIL.Image operations are synchronous and blocking. Calling them directly inside the async def download_artwork function blocked the main asyncio event loop, causing performance bottlenecks and stalling other concurrent download tasks when processing high-resolution artwork or embedding multiple images.
📊 Impact: Eliminates event loop stalls during artwork processing, significantly improving concurrent download performance when handling large albums or playlists.
🔬 Measurement: Verify by downloading an album with large artwork (rip url ... with --config.artwork.embed true and --config.artwork.save_artwork true) and monitoring CPU/asyncio execution flow.


PR created automatically by Jules for task 11033434195393069513 started by @davidjuarezdev

…king

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