Skip to content

⚡ Bolt: Offload mutagen synchronous file I/O to thread#49

Draft
davidjuarezdev wants to merge 1 commit intomainfrom
bolt/mutagen-asyncio-to-thread-1420421837364729949
Draft

⚡ Bolt: Offload mutagen synchronous file I/O to thread#49
davidjuarezdev wants to merge 1 commit intomainfrom
bolt/mutagen-asyncio-to-thread-1420421837364729949

Conversation

@davidjuarezdev
Copy link
Copy Markdown
Owner

💡 What: Wrap mutagen file load and save operations (container.get_mutagen_class and container.save_audio) in await asyncio.to_thread() within the tag_file function.

🎯 Why: The mutagen library performs heavy, synchronous disk I/O when parsing and saving audio metadata tags. Inside the tag_file async function, executing these synchronously blocks the entire asyncio event loop. This stall causes concurrent API requests and parallel media downloads to hang, drastically reducing the overall parallel download throughput of the application.

📊 Impact: Significantly improves parallel downloading throughput. The main event loop is no longer stalled during the heavy I/O of loading/saving ID3 or FLAC picture tags on large media files, reducing concurrent tail latency.

🔬 Measurement: Benchmark concurrent downloads of an album with high-res cover art. The new threaded execution should show a reduced total download time with fewer stalls between parallel track downloads compared to synchronous tagging.


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

Mutagen uses synchronous file I/O blocking the main asyncio loop. This commit moves the `get_mutagen_class` and `save_audio` operations to `asyncio.to_thread` preventing blocked concurrent downloads.

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