weichsel / ZIPFoundation

Effortless ZIP Handling in Swift
MIT License
2.31k stars 255 forks source link

Performance regression when opening lots of zip archives #311

Open LGriffioen opened 7 months ago

LGriffioen commented 7 months ago

Summary

We have a ton of uncompressed zip archives that are read and written using ZipFoundation, and users can load all of them at once in a library view. I have 8,000+ items and before the commit linked below, these could all load in 1.2s, but after it takes over 12 seconds in debug. In release mode it was 1s before and 6s after.

Both tests were done on an M1 Max machine

Steps to Reproduce

  1. create thousands of uncompressed zips, can contain multiple files
  2. load them all in a loop

Expected Results

should be very fast, even in debug

Actual Results

it's gotten ~6x slower in release, and 10x slower in debug

Regression & Version

introduced in https://github.com/weichsel/ZIPFoundation/commit/b3ca1e6f050a26b6232d70fe04937bf2a7c282ba

Related Link

weichsel commented 7 months ago

Hi Luke,

Thanks for investigating. I just skimmed over the changes and on a first glance, this change here could be the source of the performance degradation: https://github.com/weichsel/ZIPFoundation/commit/b3ca1e6f050a26b6232d70fe04937bf2a7c282ba#diff-d829f12a7b0fa38c616a3397c9ea1464287b0d0097dee344876fff88b4b28e39L316

Currently don't have the time to optimize this but if you can provide a PR, I can have a look.

LGriffioen commented 7 months ago

you're correct! adding that one check back in fixes the issue. the question is why was it removed, and what might break by restoring it?