johannesvollmer / exrs

100% Safe Rust OpenEXR file library
Other
149 stars 22 forks source link

Switch to a `Read` API that does not initialize slices, once stable #186

Open Shnatsel opened 1 year ago

Shnatsel commented 1 year ago

What can be improved or is missing?

Right now initializing slices takes to be read into takes a non-trivial amount of time. Reading is not parallelized, so it becomes a bottleneck on lightly compressed images and/or on machines with a high core count.

Implementation Approach

In the general case we need Rust's Read trait to stop requiring slices to be initialized. There's an accepted RFC and a tracking issue for it: https://github.com/rust-lang/rust/issues/78485

Technically we could make a specialized fast path for reading from in-memory buffers that bypasses the Read wrapper and can call .extend_from_slice() in the Vec instead of going through the Read implementation, but it's probably not worth the complexity.