-
Notifications
You must be signed in to change notification settings - Fork 986
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
Improve zip file iteration performance #843
Conversation
* change ZipFile enumeration to use common public struct pattern to virtual dispatch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the pooling looks sound in general, but I think it should be opt-in due to how it might affect more resource constrained setups.
src/ICSharpCode.SharpZipLib/Zip/Compression/Streams/InflaterInputStream.cs
Show resolved
Hide resolved
Thank you for the review. As I mentioned in comment, the ZipFile scenario is hard to use when you cannot control to internal input stream creation. I created a fix commit that proposes to have What do you think about the approach? I would also gladly any commits from you into this part shaping the solution towards your liking, but also hoping that the benchmark's |
I think that would be a good compromise. I am not sure about making the pool public though... Perhaps there should be a public singleton that maps to the internals of the pool. That way we have a clear consumer API for global library tweaks... Or perhaps I am just overthinking it. The initial value would need to be 0 though, as the goal is to not accidently break anything (but again, maybe I am making this into a larger issue than it needs to be..) |
* Make InflaterPool size configurable via SharpZipLibOptions.InflaterPoolSize
It's always good to keep downstream consumers happy! 😉 I've force pushed a proposal of adding root level static class for global options, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! The performance improvements are nice and this should not interfere with any existing usage (afaict).
When traversing large zip files I noticed that SharpZipLib was allocating quite a lot of memory. So I found out that by pooling of costly
Inflator
instances a lot of that can be rectified. There's now newPooledInflator
type that can be used by the library itself and is known to be safe to pool (it's rented from pool or is otherwise instance created by the library itself).I also changed ZipFile to follow the common
public struct
enumerator pattern found in BCL data structures that removes unnecessary allocationsBenchmark test case updated and now targets oldest supported runtimes (.NET 4.6.2 and .NET 6.0). Unsupported runtimes are not installed by default.
Results
ICSharpCode.SharpZipLib.Benchmark.Zip.ZipInputStream
I certify that I own, and have sufficient rights to contribute, all source code and related material intended to be compiled or integrated with the source code for the SharpZipLib open source product (the "Contribution"). My Contribution is licensed under the MIT License.