Skip to content

Performance deterioration in 1.0.0 in comparison to 0.86.0 #289

Closed

Description

@decipherer

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

Version of SharpZipLib

0.86.0.518 vs 1.0.0.999

Obtained from (only keep the relevant lines)

  • Package installed using NuGet

Activity

  1. piksel commented on Dec 10, 2018

    @piksel
    Member

    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...

  2. MarcWils commented on Dec 11, 2018

    @MarcWils

    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

  3. piksel commented on Dec 11, 2018

    @piksel
    Member

    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!

  4. decipherer commented on Dec 12, 2018

    @decipherer
    ContributorAuthor

    Great work guys!

  5. decipherer commented on Dec 12, 2018

    @decipherer
    ContributorAuthor

    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

  6. piksel commented on Dec 16, 2018

    @piksel
    Member

    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?

  7. piksel commented on Jan 3, 2019

    @piksel
    Member

    I am closing this as two fixes for the issue has been merged.

  8. decipherer commented on Jan 8, 2019

    @decipherer
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions