perf: faster zip entry extraction #1661
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently ZipFile read will scan entire file to read each entry's local file header on each request for book page image.
This can be quite a slow operation depending on archive file size. In my tests 800mb archive with ~400 entries stored on hdd takes ~3 seconds on initial read on Linux system.
After initial read OS will cache file and subsequent reads become really fast ~50-100ms, but in my opinion it's better to not rely on OS for caching
If we only read central directory header entry retrieval takes ~100-150ms instead of 3 seconds which is about 30 times faster
The downside to only reading central directory is that filename can use Unicode extra field and that field is (for some reason) only added to local file header.
In that case retrieving entry might fail and we fallback to iterating each entry local file header and set name from Unicode extra field if it exists
I've also updated Apache Compress library version which deprecated ZipFile constructor calls and replaced it with Builders