You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Performance deterioration in 1.0.0 in comparison to 0.86.0 #289
We have been using version 0.86 of sharpziplib up till now. After updating to 1.0.0 we notice some welcomed improvements, but unfortunately also a big performance deterioration.
Steps to reproduce
Read a file using ZipInputStream in version 0.86 and record the duration
Then read the same file using ZipInputStream in version 1.0 and record the duration
Compare the two durations
Expected behavior
The two durations should be roughly the same
Actual behavior
The duration for version 1.0.0 is consistently a lot higher.
As an example, on my machine I notice the following difference in duration:
90MB file:
Version 0.86.0: 0.62s
Version 1.0.0: 3.3s
2GB file:
Version 0.86.0: 21.47s
Version 1.0.0: 81.31s
Both files were zipped using 7zip, using deflate, compression level normal , 32Kb Dictionary size, 32 Word size
Version 1.0.0 seems to be about 4-5 times slower in decompressing a file than version 0.86.0
That's odd. Unfortunately it's hard to know exactly what has changed since 0.86 since there hadn't been a release for many years before 1.0.
Since you already have a good test case, would you mind running both cases through profiling?
I could not find any obvious changes that would yield such a drastic decrease in performance, although the switch to the new Stream API (IDisposable instead of Close) might be the culprit due to side effects somehow...
I ran both versions through a VS profiler (see link below).
There seems to be a hot path in Checksum.Adler32.Update: 55% exclusive samples in v1.0.0 versus 10% in v0.86.0.
One thing that pops out, is that in v1.0.0 the Update method is called for each individual byte. Maybe this causes to much overhead (stack unwinding, etc.)
Looking at the code it seems the Adler checksum is not used for (PK)Zip or GZip files. Therefore, it seems like unnecessary overhead to calculate the Adler checksum. Since the necessity of the Adler checksum can be easily deducted from the constructor arguments noZlibHeaderOrFooter (Deflater) and noHeader (Inflater) it would make sense not to calculate it when it's not necessary. Even for the more optimized version it can save quite some time.
-edit-: I've created a pull request with a possible solution to not calculating the Adler checksum if it's not necessary: #293
Another good catch. Why the checksum is calculated just to be discarded is beyond me. The intent to do so is clearly indicated by the arguments, so why bother?
Great! We indeed see a big improvement in performance, but unfortunately not everything is as fast as 0.86.0 yet.
I did some testing on my machine with a 2GB file:
0.86.0 using ZipFile to get entries: 9.5 seconds
0.86.0 using ZipInputStream to get entries: 16.4 seconds
1.1.0 using ZipFile to get entries: 5.6 seconds
1.1.0 using ZipInputStream to get entries: 23.4 seconds
So a big improvement when using ZipFile, but still a slight deterioration when using ZipInputStream.
I did some profiling and the problem is in the CRC update method, specifically the overhead that ArraySegment introduces.
I'm preparing a pull request to fix this.
-edit- Just created the pull request, after the changes I'm getting the following result:
1.1.0 (with fix) using ZipInputStream to get entries: 15.4 seconds
So that's on par with 0.86.0.
Activity
piksel commentedon Dec 10, 2018
That's odd. Unfortunately it's hard to know exactly what has changed since 0.86 since there hadn't been a release for many years before 1.0.
Since you already have a good test case, would you mind running both cases through profiling?
I could not find any obvious changes that would yield such a drastic decrease in performance, although the switch to the new Stream API (IDisposable instead of Close) might be the culprit due to side effects somehow...
MarcWils commentedon Dec 11, 2018
I ran both versions through a VS profiler (see link below).
There seems to be a hot path in Checksum.Adler32.Update: 55% exclusive samples in v1.0.0 versus 10% in v0.86.0.
One thing that pops out, is that in v1.0.0 the Update method is called for each individual byte. Maybe this causes to much overhead (stack unwinding, etc.)
Profiling reports: https://1drv.ms/u/s!AppRBW7nPNmIjJVZGBlq0nnwMMY_EA
piksel commentedon Dec 11, 2018
Good catch!
Adler32 Hashing of 256 MiB using the current implementation:
7.5874 second(s)Using the optimized version that was present before the introduction of ArraySegment:
1.5796 second(s)I wrote a test case and a revert to the optimized version and will merge them before the next release!
decipherer commentedon Dec 12, 2018
Great work guys!
decipherer commentedon Dec 12, 2018
Looking at the code it seems the Adler checksum is not used for (PK)Zip or GZip files. Therefore, it seems like unnecessary overhead to calculate the Adler checksum. Since the necessity of the Adler checksum can be easily deducted from the constructor arguments noZlibHeaderOrFooter (Deflater) and noHeader (Inflater) it would make sense not to calculate it when it's not necessary. Even for the more optimized version it can save quite some time.
-edit-: I've created a pull request with a possible solution to not calculating the Adler checksum if it's not necessary: #293
piksel commentedon Dec 16, 2018
Another good catch. Why the checksum is calculated just to be discarded is beyond me. The intent to do so is clearly indicated by the arguments, so why bother?
piksel commentedon Jan 3, 2019
I am closing this as two fixes for the issue has been merged.
decipherer commentedon Jan 8, 2019
Great! We indeed see a big improvement in performance, but unfortunately not everything is as fast as 0.86.0 yet.
I did some testing on my machine with a 2GB file:
0.86.0 using ZipFile to get entries: 9.5 seconds
0.86.0 using ZipInputStream to get entries: 16.4 seconds
1.1.0 using ZipFile to get entries: 5.6 seconds
1.1.0 using ZipInputStream to get entries: 23.4 seconds
So a big improvement when using ZipFile, but still a slight deterioration when using ZipInputStream.
I did some profiling and the problem is in the CRC update method, specifically the overhead that ArraySegment introduces.
I'm preparing a pull request to fix this.
-edit- Just created the pull request, after the changes I'm getting the following result:
1.1.0 (with fix) using ZipInputStream to get entries: 15.4 seconds
So that's on par with 0.86.0.