rs-async-zip icon indicating copy to clipboard operation
rs-async-zip copied to clipboard

async_zip::tokio::read::fs::ZipFileReader::new has no buffering

Open link2xt opened this issue 11 months ago • 1 comments

Readme shows the correct way to open files manually and wrapping them into BufReader: https://github.com/Majored/rs-async-zip/blob/527bda9d58c1ba1fa973a0faeb68dce91fa4ffe4/README.md?plain=1#L46

But there is another API async_zip::tokio::read::fs::ZipFileReader::new that simply opens a file without any buffering. On Android with SD card it's very noticeable that this is slow and even on laptops with SSD this is measurably slower as tested by @Hocuri in https://github.com/Hocuri/tst-rs/ (300 ms vs <1ms in the test, and flamegraph shows that most of the time is spent in poll_read)

Probably this API should wrap the file into BufReader internally.

I worked around this by opening the file and wrapping it into BufReader myself as README suggests: https://github.com/deltachat/deltachat-core-rust/pull/6482

link2xt avatar Jan 27 '25 18:01 link2xt

Yep, good spot - thanks. Just had a thought that this reader is essentially akin to a generator in the sense that it could be converted to a base reader type where the caller provides a generator for values which impl AsyncBufRead. That way we just provide that base a new reader that way instead of this being tied to tokio's File.

Will leave this open until that's been added though. 👍

Majored avatar Jan 31 '25 21:01 Majored