python / cpython

The Python programming language
https://www.python.org
Other
62.77k stars 30.08k forks source link

LZMA MultiThreading XZ compression support #114953

Open mkomet opened 8 months ago

mkomet commented 8 months ago

Feature or enhancement

Proposal:

import lzma
data = b'8'*(2 << 30)
# Current API, using single-threaded pool in liblzma,
# using `lzma_easy_encoder` / `lzma_stream_encoder`
lzma.compress(data)
# Compress using XZ underlying 4 background threads, using `lzma_stream_encoder_mt`
lzma.compress(data, threads=4)
# Use thread pool based on nproc (`lzma_cputhreads`)
lzma.compress(data, threads=0)
# Support in `LZMAFile` class
with LZMAFile(BytesIO(data), threads=4) as f:
    pass
# Throws ValueError for negative `threads`
lzma.compress(data, threads=-1)

Notes:

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

https://discuss.python.org/t/multi-threaded-lzma/26708/3

Linked PRs

Artoria2e5 commented 7 months ago

Thanks for the issue and the PR!