Closed lahma closed 1 year ago
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 InflaterPool.Size
which is only public member and allows to disable the pooling by supplying a value of 0 or less.
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 ZipFile
API usage would be covered.
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..)
It's always good to keep downstream consumers happy! 😉 I've force pushed a proposal of adding root level static class for global options, SharpZipLibOptions
, which has now sole property of InflaterPoolSize
which defaults to 0. Benchmark updated to set the value to 4 (allocations still down 70%).
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.