zip-rs / zip-old

Zip implementation in Rust
MIT License
731 stars 204 forks source link

Very slow archive opening #387

Closed ClementNerma closed 1 year ago

ClementNerma commented 1 year ago

Hi there!

I'm currently using zip for a comic reader project, and have troubles with loading files.

Basically, calling ZipArchive::new(File::open(...)) is slow as hell. File::open() runs very quickly, but ZipArchive::new() is very slow. In release mode, on a fast drive, it takes 7 secondes to create the archive from a 750 MB ZIP file.

Note that I'm not talking about extracting the files here, just calling ZipArchive::new().

I need to count the number of files and list them when opening an archive, but as this single function takes so long I can't do anything before 7s on this file, which is really slow.

Any idea on why this happens? How could I improve performances here?

Thanks in advance for your help :)

NobodyXu commented 1 year ago

ZipArchive::new needs to fine and parse the CentralDirectoryEnd, then read and parse the header for every entry.

I think wrapping the File with std::io::BufReader should help improve performance of ZipArchive::new, since it does read entries linearly.

ClementNerma commented 1 year ago

What a timing, that's exactly what I've just done before reading your comment and it works perfectly ^^

Now it takes only a few milliseconds.

Thanks!