Bindings to the seekable variant of the ZSTD compression format

#11 Flexibilize parallel compress a bit

Opened by darleybarreto on February 27, 2022
darleybarreto on February 27, 2022

I was trying to expose the functions to Python with PyO3 and there were/are some limitations around parallel compression. I’ve made some changes by replacing threadpool with rayon’s scoped thread pool to remove the need for 'static bound. In order to compress a vec (instead of an array) I need to implement Dst for Vec<u8>, but then in compress_frame:

let mut dst = D::new();

gives an empty vec, which crashes. With an array, this is known at compile time, so it works just fine.

I think passing a flag to parallel_compress and compress_frame indicating to create something with capacity would not be the right move, eg

fn compress_frame<D: Dst>(src: &[u8], level: usize, capacity: Option<usize>) -> Result<CompressedFrame<D>, Error> {
    if Some(cap) = capacity {
        let mut dst = D::with_capacity(cap);
    } else {
        let mut dst = D::new();
    }
    ...
}

@pmeunier would you have an advice here?

darleybarreto on February 27, 2022

(I’m having trouble to push the changes to the Nest)

Edit: Now the changes are all set.

darleybarreto added a change on February 27, 2022
SWKKLREPG5MBV3AWEYHM5RYNNMLV355FHJMU2WFJ3UL5LDSDMTQQC
darleybarreto added a change on February 27, 2022
Removing 'static from compress_frame by EA5TmpmTEqSKPj4q9VNMvmRVbN4j11YWX8FSxAAoTVCp,
3HPQTZ5KRH5RE5VF4OXVPDEEJUI3KYWX5MXI5E7KNGGTGL52MMDAC
darleybarreto added a change on February 27, 2022
SWKKLREPG5MBV3AWEYHM5RYNNMLV355FHJMU2WFJ3UL5LDSDMTQQC
darleybarreto added a change on February 27, 2022
Adding the most obvious fix. by EA5TmpmTEqSKPj4q9VNMvmRVbN4j11YWX8FSxAAoTVCp,
MWBPX2WV5JE5ABT3OZFA225IXEU2KVQWSADEXLSL46NLK7SGPFSAC
darleybarreto on February 27, 2022

First, I’m not sure why my pushes keep adding these (no change message) empty changes.

This last change I uploaded is the simpler fix I could think of, as a PoC. There must be a much better (Rust) way of doing it.