Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise buffer usage in zip walk functions #94

Merged
merged 9 commits into from
Feb 4, 2022

Conversation

glynternet
Copy link
Contributor

We can reuse buffers in the Reader struct to reduce the number of allocations when walking a zip.
The pointer passed to the handler will now point to the same memory address but we have already stated that the file should only be used during the duration of the WalkFn callback so this is fine.

The largest improvements are for zips containing many files but we still get a 15% speedup from zips containing as little as 10 files. These optimisations only improve the overhead of scanning a zip file, not processing contents etc.

$ benchstat /tmp/before /tmp/after
name                       old time/op    new time/op    delta
WalkZipReaderAt/10-16        6.03µs ± 1%    5.09µs ± 3%  -15.66%  (p=0.004 n=5+6)
WalkZipReaderAt/100-16       24.2µs ± 1%    14.8µs ± 2%  -39.03%  (p=0.002 n=6+6)
WalkZipReaderAt/1000-16       215µs ± 2%     109µs ± 0%  -49.25%  (p=0.004 n=6+5)
WalkZipReaderAt/10000-16     2.31ms ± 1%    1.11ms ± 1%  -51.76%  (p=0.004 n=6+5)
WalkZipReaderAt/100000-16    21.6ms ± 2%    11.7ms ± 2%  -46.06%  (p=0.002 n=6+6)

name                       old alloc/op   new alloc/op   delta
WalkZipReaderAt/10-16        8.08kB ± 0%    5.70kB ± 0%  -29.50%  (p=0.002 n=6+6)
WalkZipReaderAt/100-16       30.0kB ± 0%     5.9kB ± 0%  -80.45%  (p=0.002 n=6+6)
WalkZipReaderAt/1000-16       252kB ± 0%       9kB ± 0%  -96.51%  (p=0.002 n=6+6)
WalkZipReaderAt/10000-16     2.48MB ± 0%    0.04MB ± 0%  -98.20%  (p=0.000 n=5+6)
WalkZipReaderAt/100000-16    25.0MB ± 0%     0.5MB ± 0%  -97.90%  (p=0.002 n=6+6)

name                       old allocs/op  new allocs/op  delta
WalkZipReaderAt/10-16          39.0 ± 0%       9.0 ± 0%  -76.92%  (p=0.002 n=6+6)
WalkZipReaderAt/100-16          399 ± 0%       100 ± 0%  -74.94%  (p=0.002 n=6+6)
WalkZipReaderAt/1000-16       4.00k ± 0%     1.00k ± 0%  -74.93%  (p=0.002 n=6+6)
WalkZipReaderAt/10000-16      40.0k ± 0%     10.0k ± 0%  -74.99%  (p=0.002 n=6+6)
WalkZipReaderAt/100000-16      400k ± 0%      100k ± 0%  -75.00%  (p=0.002 n=6+6)

@changelog-app
Copy link

changelog-app bot commented Feb 2, 2022

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Some optimisations have been made which should reduce the resource overhead required when inspecting zip files, such as .jars, .wars, .pars, etc.

Check the box to generate changelog(s)

  • Generate changelog entry

@hpryce
Copy link
Contributor

hpryce commented Feb 4, 2022

👍

@bulldozer-bot bulldozer-bot bot merged commit 9f7c82a into develop Feb 4, 2022
@bulldozer-bot bulldozer-bot bot deleted the gh/optimise-zipreader-buffers branch February 4, 2022 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants