Skip to content
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

Multithreading: num_threads and no-GIL #69

Merged
merged 2 commits into from
Oct 7, 2024
Merged

Conversation

Piezoid
Copy link
Contributor

@Piezoid Piezoid commented Oct 6, 2024

Adds support for the num_threads parameter and GIL releasing in the Encoder/Decoder.

For batch conversions with ample memory, transcoding multiple files concurrently is often more efficient, but requires reducing or disabling libjxl's parallelism. Releasing the GIL enables concurrent jxl operations in a single python process.

Encoder parallelism can be configured via Image.save(num_threads=<n>). The decoder supports this too, though Pillow lacks a direct way to pass arguments. A settable module constant might be an option—open to feedback on this.

Behavior mirrors cjxl's --num_threads parameter:

-1: machine default, 0: single-threaded.

@Isotr0py Isotr0py self-requested a review October 7, 2024 02:55
Copy link
Owner

@Isotr0py Isotr0py left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for your great contribution!

@Isotr0py Isotr0py merged commit 95542a1 into Isotr0py:main Oct 7, 2024
8 checks passed
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.

2 participants