Skip to content

Conversation

@edwardneal
Copy link
Contributor

@edwardneal edwardneal commented Mar 16, 2025

The GZipStream class is capable of parsing multiple, concatenated GZip data streams. If it reaches the end of a GZip stream and it detects that there's more GZip data remaining to process, it currently disposes of its existing ZLibStreamHandle and instantiates a new one with the same settings. As a result, it frees and reallocates enough memory for the ZLibStreamHandle (including the ZStream PAL structure it wraps) and the z_stream wrapped by the PAL structure. It also calls the ZLib methods inflateEnd and inflateInit2, reconstructing a brand new set of inflater state.

This PR changes that logic to call inflateReset2 within ZLib. This means that we can reset and reuse the existing ZLibStreamHandle rather than allocating a new one. It also provides a modest reduction in execution time and memory usage.

Full benchmark results are below, but to summarise:

  • Overall, no significant changes to execution time or memory usage for GZipStream processing of a single GZip stream.
  • Two 3%/6% deviations when compressing a single 5KB stream with compression modes of NoCompression and Fastest, respectively. I'm not sure why, but my changes aren't invoked unless there are multiple streams so I think it's pretty likely that it's just background noise.
  • Around a 2.5KB increase in code size. Based on other changes, the overall chain of GZipStream/DeflateStream/Inflater/ZLibStreamHandle seems to be close to an inlining threshold; we've replaced two of the PInvokes with one, so I think we've reduced the code size of Inflater.ResetStreamForLeftoverInput by enough to cross that threshold.
  • Total allocated memory over the lifespan of the benchmark now remains constant at 440-446 bytes, rather than rising as GZipStream processes each concatenated stream of GZip data. This eliminates the allocation of around 64-80 bytes of managed memory per data stream, plus more unmanaged memory.
  • Approximate 400ns reduction in execution time per concatenated stream.
  • Initialization only happens once per data stream, so this has the largest impact (~35%) with a large number of small data streams. As expected, this impact decreases as the size of each data stream (and thus the number of reads) increases, or as the number of data streams decreases.
Benchmark results
Method Job Toolchain BytesPerStream NumberOfStreams CompressionLevel Mean Error StdDev Median Ratio RatioSD Gen0 Code Size Allocated Alloc Ratio
Benchmark Baseline .NET 9.0 256 1 Optimal 1.146 μs 0.0146 μs 0.0136 μs 1.137 μs 1.00 0.02 0.0172 10,252 B 440 B 1.00
Benchmark CoreRun CoreRun 256 1 Optimal 1.120 μs 0.0218 μs 0.0223 μs 1.106 μs 0.98 0.02 0.0172 12,574 B 440 B 1.00
Benchmark Baseline .NET 9.0 256 1 Fastest 1.164 μs 0.0049 μs 0.0046 μs 1.163 μs 1.00 0.01 0.0172 10,361 B 440 B 1.00
Benchmark CoreRun CoreRun 256 1 Fastest 1.158 μs 0.0225 μs 0.0293 μs 1.148 μs 0.99 0.02 0.0172 12,574 B 440 B 1.00
Benchmark Baseline .NET 9.0 256 1 NoCompression 1.098 μs 0.0060 μs 0.0056 μs 1.097 μs 1.00 0.01 0.0172 10,367 B 440 B 1.00
Benchmark CoreRun CoreRun 256 1 NoCompression 1.107 μs 0.0207 μs 0.0213 μs 1.116 μs 1.01 0.02 0.0172 12,575 B 440 B 1.00
Benchmark Baseline .NET 9.0 256 1 SmallestSize 1.158 μs 0.0133 μs 0.0124 μs 1.157 μs 1.00 0.01 0.0172 10,231 B 440 B 1.00
Benchmark CoreRun CoreRun 256 1 SmallestSize 1.123 μs 0.0054 μs 0.0045 μs 1.123 μs 0.97 0.01 0.0172 12,574 B 440 B 1.00
Benchmark Baseline .NET 9.0 256 5 Optimal 5.466 μs 0.1069 μs 0.1098 μs 5.427 μs 1.00 0.03 0.0229 10,262 B 760 B 1.00
Benchmark CoreRun CoreRun 256 5 Optimal 3.909 μs 0.0103 μs 0.0096 μs 3.907 μs 0.72 0.01 0.0153 12,991 B 440 B 0.58
Benchmark Baseline .NET 9.0 256 5 Fastest 8.537 μs 0.0291 μs 0.0258 μs 8.539 μs 1.00 0.00 0.0153 10,465 B 760 B 1.00
Benchmark CoreRun CoreRun 256 5 Fastest 7.329 μs 0.0285 μs 0.0253 μs 7.330 μs 0.86 0.00 0.0153 12,991 B 440 B 0.58
Benchmark Baseline .NET 9.0 256 5 NoCompression 3.918 μs 0.0488 μs 0.0433 μs 3.919 μs 1.00 0.02 0.0229 10,310 B 760 B 1.00
Benchmark CoreRun CoreRun 256 5 NoCompression 2.460 μs 0.0170 μs 0.0151 μs 2.464 μs 0.63 0.01 0.0153 12,995 B 440 B 0.58
Benchmark Baseline .NET 9.0 256 5 SmallestSize 5.467 μs 0.1051 μs 0.0983 μs 5.419 μs 1.00 0.02 0.0229 10,416 B 760 B 1.00
Benchmark CoreRun CoreRun 256 5 SmallestSize 3.808 μs 0.0074 μs 0.0062 μs 3.809 μs 0.70 0.01 0.0153 12,993 B 440 B 0.58
Benchmark Baseline .NET 9.0 256 100 Optimal 101.966 μs 1.1713 μs 1.0383 μs 101.447 μs 1.00 0.01 0.2441 10,429 B 8360 B 1.00
Benchmark CoreRun CoreRun 256 100 Optimal 65.402 μs 0.3321 μs 0.3106 μs 65.406 μs 0.64 0.01 - 13,005 B 440 B 0.05
Benchmark Baseline .NET 9.0 256 100 Fastest 184.850 μs 0.4663 μs 0.4361 μs 184.848 μs 1.00 0.00 0.2441 10,323 B 8360 B 1.00
Benchmark CoreRun CoreRun 256 100 Fastest 156.171 μs 0.5128 μs 0.4282 μs 156.062 μs 0.84 0.00 - 13,028 B 440 B 0.05
Benchmark Baseline .NET 9.0 256 100 NoCompression 67.921 μs 0.2533 μs 0.2245 μs 67.845 μs 1.00 0.00 0.2441 10,432 B 8360 B 1.00
Benchmark CoreRun CoreRun 256 100 NoCompression 32.912 μs 0.0695 μs 0.0650 μs 32.894 μs 0.48 0.00 - 13,009 B 440 B 0.05
Benchmark Baseline .NET 9.0 256 100 SmallestSize 104.883 μs 1.9652 μs 1.8383 μs 105.714 μs 1.00 0.02 0.2441 10,294 B 8360 B 1.00
Benchmark CoreRun CoreRun 256 100 SmallestSize 66.117 μs 0.1656 μs 0.1468 μs 66.106 μs 0.63 0.01 - 13,005 B 440 B 0.05
Benchmark Baseline .NET 9.0 256 500 Optimal 518.926 μs 10.3246 μs 11.8898 μs 517.591 μs 1.00 0.03 0.9766 10,289 B 40361 B 1.00
Benchmark CoreRun CoreRun 256 500 Optimal 328.535 μs 0.4633 μs 0.4334 μs 328.641 μs 0.63 0.01 - 14,138 B 440 B 0.01
Benchmark Baseline .NET 9.0 256 500 Fastest 937.781 μs 15.4114 μs 14.4158 μs 943.477 μs 1.00 0.02 0.9766 10,353 B 40361 B 1.00
Benchmark CoreRun CoreRun 256 500 Fastest 771.680 μs 1.1465 μs 1.0724 μs 771.535 μs 0.82 0.01 - 14,048 B 440 B 0.01
Benchmark Baseline .NET 9.0 256 500 NoCompression 340.355 μs 3.1362 μs 2.6188 μs 340.221 μs 1.00 0.01 1.4648 10,311 B 40360 B 1.00
Benchmark CoreRun CoreRun 256 500 NoCompression 160.700 μs 0.3135 μs 0.2779 μs 160.783 μs 0.47 0.00 - 13,958 B 440 B 0.01
Benchmark Baseline .NET 9.0 256 500 SmallestSize 515.323 μs 4.9111 μs 4.1010 μs 514.186 μs 1.00 0.01 0.9766 10,328 B 40361 B 1.00
Benchmark CoreRun CoreRun 256 500 SmallestSize 326.221 μs 0.7921 μs 0.7022 μs 326.153 μs 0.63 0.00 - 13,798 B 440 B 0.01
Benchmark Baseline .NET 9.0 256 1000 Optimal 1,035.003 μs 1.9446 μs 1.7238 μs 1,034.868 μs 1.00 0.00 1.9531 10,313 B 80361 B 1.000
Benchmark CoreRun CoreRun 256 1000 Optimal 656.400 μs 1.2565 μs 1.1754 μs 656.190 μs 0.63 0.00 - 14,025 B 441 B 0.005
Benchmark Baseline .NET 9.0 256 1000 Fastest 1,891.270 μs 5.0383 μs 4.7128 μs 1,891.738 μs 1.00 0.00 1.9531 10,565 B 80361 B 1.000
Benchmark CoreRun CoreRun 256 1000 Fastest 1,538.277 μs 4.0728 μs 3.8097 μs 1,537.606 μs 0.81 0.00 - 14,116 B 441 B 0.005
Benchmark Baseline .NET 9.0 256 1000 NoCompression 711.990 μs 14.1921 μs 23.3181 μs 727.517 μs 1.00 0.05 2.9297 10,311 B 80361 B 1.000
Benchmark CoreRun CoreRun 256 1000 NoCompression 319.639 μs 0.8781 μs 0.8214 μs 319.620 μs 0.45 0.01 - 14,080 B 440 B 0.005
Benchmark Baseline .NET 9.0 256 1000 SmallestSize 1,068.692 μs 14.2208 μs 13.3022 μs 1,076.515 μs 1.00 0.02 1.9531 10,915 B 80361 B 1.000
Benchmark CoreRun CoreRun 256 1000 SmallestSize 657.786 μs 1.2852 μs 1.1393 μs 657.726 μs 0.62 0.01 - 14,025 B 441 B 0.005
Benchmark Baseline .NET 9.0 1024 1 Optimal 2.053 μs 0.0106 μs 0.0094 μs 2.052 μs 1.00 0.01 0.0153 10,062 B 440 B 1.00
Benchmark CoreRun CoreRun 1024 1 Optimal 2.008 μs 0.0090 μs 0.0079 μs 2.009 μs 0.98 0.01 0.0153 12,352 B 440 B 1.00
Benchmark Baseline .NET 9.0 1024 1 Fastest 2.084 μs 0.0101 μs 0.0095 μs 2.085 μs 1.00 0.01 0.0153 10,110 B 440 B 1.00
Benchmark CoreRun CoreRun 1024 1 Fastest 2.082 μs 0.0271 μs 0.0254 μs 2.092 μs 1.00 0.01 0.0153 12,352 B 440 B 1.00
Benchmark Baseline .NET 9.0 1024 1 NoCompression 1.649 μs 0.0075 μs 0.0070 μs 1.650 μs 1.00 0.01 0.0172 9,969 B 440 B 1.00
Benchmark CoreRun CoreRun 1024 1 NoCompression 1.598 μs 0.0048 μs 0.0044 μs 1.598 μs 0.97 0.00 0.0172 12,352 B 440 B 1.00
Benchmark Baseline .NET 9.0 1024 1 SmallestSize 2.058 μs 0.0076 μs 0.0067 μs 2.057 μs 1.00 0.00 0.0153 10,067 B 440 B 1.00
Benchmark CoreRun CoreRun 1024 1 SmallestSize 2.063 μs 0.0388 μs 0.0363 μs 2.048 μs 1.00 0.02 0.0153 12,352 B 440 B 1.00
Benchmark Baseline .NET 9.0 1024 5 Optimal 12.479 μs 0.1196 μs 0.1119 μs 12.529 μs 1.00 0.01 0.0153 10,275 B 760 B 1.00
Benchmark CoreRun CoreRun 1024 5 Optimal 10.978 μs 0.0318 μs 0.0298 μs 10.974 μs 0.88 0.01 0.0153 12,996 B 440 B 0.58
Benchmark Baseline .NET 9.0 1024 5 Fastest 12.371 μs 0.0450 μs 0.0399 μs 12.363 μs 1.00 0.00 0.0153 10,466 B 760 B 1.00
Benchmark CoreRun CoreRun 1024 5 Fastest 11.067 μs 0.0202 μs 0.0168 μs 11.070 μs 0.89 0.00 0.0153 12,996 B 440 B 0.58
Benchmark Baseline .NET 9.0 1024 5 NoCompression 6.632 μs 0.0151 μs 0.0141 μs 6.627 μs 1.00 0.00 0.0229 10,314 B 760 B 1.00
Benchmark CoreRun CoreRun 1024 5 NoCompression 5.083 μs 0.0356 μs 0.0333 μs 5.080 μs 0.77 0.01 0.0153 12,996 B 440 B 0.58
Benchmark Baseline .NET 9.0 1024 5 SmallestSize 12.521 μs 0.1641 μs 0.1535 μs 12.424 μs 1.00 0.02 0.0153 10,418 B 760 B 1.00
Benchmark CoreRun CoreRun 1024 5 SmallestSize 11.128 μs 0.0371 μs 0.0329 μs 11.119 μs 0.89 0.01 0.0153 12,996 B 440 B 0.58
Benchmark Baseline .NET 9.0 1024 100 Optimal 260.125 μs 1.4054 μs 1.3146 μs 260.380 μs 1.00 0.01 - 10,284 B 8360 B 1.00
Benchmark CoreRun CoreRun 1024 100 Optimal 224.015 μs 0.3704 μs 0.2892 μs 224.118 μs 0.86 0.00 - 13,085 B 440 B 0.05
Benchmark Baseline .NET 9.0 1024 100 Fastest 257.576 μs 2.4113 μs 2.2555 μs 256.554 μs 1.00 0.01 - 10,323 B 8360 B 1.00
Benchmark CoreRun CoreRun 1024 100 Fastest 223.143 μs 0.3795 μs 0.3169 μs 223.069 μs 0.87 0.01 - 13,087 B 440 B 0.05
Benchmark Baseline .NET 9.0 1024 100 NoCompression 127.662 μs 0.4571 μs 0.4276 μs 127.615 μs 1.00 0.00 0.2441 10,311 B 8360 B 1.00
Benchmark CoreRun CoreRun 1024 100 NoCompression 88.929 μs 0.1146 μs 0.1016 μs 88.948 μs 0.70 0.00 - 13,038 B 440 B 0.05
Benchmark Baseline .NET 9.0 1024 100 SmallestSize 260.264 μs 0.5732 μs 0.5362 μs 260.115 μs 1.00 0.00 - 10,284 B 8360 B 1.00
Benchmark CoreRun CoreRun 1024 100 SmallestSize 231.321 μs 0.4065 μs 0.3604 μs 231.427 μs 0.89 0.00 - 13,083 B 440 B 0.05
Benchmark Baseline .NET 9.0 1024 500 Optimal 1,295.258 μs 12.1798 μs 11.3930 μs 1,290.564 μs 1.00 0.01 - 10,328 B 40361 B 1.00
Benchmark CoreRun CoreRun 1024 500 Optimal 1,129.203 μs 2.1957 μs 2.0539 μs 1,128.585 μs 0.87 0.01 - 14,091 B 441 B 0.01
Benchmark Baseline .NET 9.0 1024 500 Fastest 1,287.120 μs 13.9420 μs 13.0414 μs 1,292.967 μs 1.00 0.01 - 10,330 B 40361 B 1.00
Benchmark CoreRun CoreRun 1024 500 Fastest 1,106.191 μs 3.2960 μs 2.9218 μs 1,106.369 μs 0.86 0.01 - 14,058 B 441 B 0.01
Benchmark Baseline .NET 9.0 1024 500 NoCompression 648.401 μs 4.8279 μs 4.5160 μs 646.080 μs 1.00 0.01 0.9766 10,350 B 40361 B 1.00
Benchmark CoreRun CoreRun 1024 500 NoCompression 437.942 μs 0.7825 μs 0.7320 μs 437.881 μs 0.68 0.00 - 14,037 B 440 B 0.01
Benchmark Baseline .NET 9.0 1024 500 SmallestSize 1,312.002 μs 5.5468 μs 4.3305 μs 1,310.821 μs 1.00 0.00 - 10,360 B 40361 B 1.00
Benchmark CoreRun CoreRun 1024 500 SmallestSize 1,141.382 μs 2.1427 μs 1.8994 μs 1,141.095 μs 0.87 0.00 - 14,113 B 441 B 0.01
Benchmark Baseline .NET 9.0 1024 1000 Optimal 2,619.970 μs 22.8361 μs 21.3609 μs 2,607.903 μs 1.00 0.01 - 10,667 B 80363 B 1.000
Benchmark CoreRun CoreRun 1024 1000 Optimal 2,239.317 μs 5.0343 μs 4.7091 μs 2,239.622 μs 0.85 0.01 - 13,716 B 443 B 0.006
Benchmark Baseline .NET 9.0 1024 1000 Fastest 2,585.357 μs 23.0009 μs 20.3897 μs 2,592.103 μs 1.00 0.01 - 10,718 B 80363 B 1.000
Benchmark CoreRun CoreRun 1024 1000 Fastest 2,234.296 μs 5.4321 μs 5.0812 μs 2,234.379 μs 0.86 0.01 - 14,065 B 442 B 0.006
Benchmark Baseline .NET 9.0 1024 1000 NoCompression 1,233.317 μs 4.3887 μs 4.1052 μs 1,232.006 μs 1.00 0.00 1.9531 10,776 B 80361 B 1.000
Benchmark CoreRun CoreRun 1024 1000 NoCompression 887.404 μs 2.8762 μs 2.6904 μs 888.043 μs 0.72 0.00 - 14,042 B 440 B 0.005
Benchmark Baseline .NET 9.0 1024 1000 SmallestSize 2,600.479 μs 4.3503 μs 4.0693 μs 2,601.124 μs 1.00 0.00 - 10,779 B 80362 B 1.000
Benchmark CoreRun CoreRun 1024 1000 SmallestSize 2,274.596 μs 5.4910 μs 4.8676 μs 2,273.774 μs 0.87 0.00 - 14,120 B 442 B 0.006
Benchmark Baseline .NET 9.0 5120 1 Optimal 8.152 μs 0.0204 μs 0.0181 μs 8.156 μs 1.00 0.00 0.0153 10,119 B 440 B 1.00
Benchmark CoreRun CoreRun 5120 1 Optimal 8.166 μs 0.0129 μs 0.0114 μs 8.165 μs 1.00 0.00 0.0153 12,280 B 440 B 1.00
Benchmark Baseline .NET 9.0 5120 1 Fastest 6.382 μs 0.0183 μs 0.0162 μs 6.382 μs 1.00 0.00 0.0153 10,067 B 440 B 1.00
Benchmark CoreRun CoreRun 5120 1 Fastest 6.741 μs 0.0113 μs 0.0100 μs 6.744 μs 1.06 0.00 0.0153 12,280 B 440 B 1.00
Benchmark Baseline .NET 9.0 5120 1 NoCompression 4.390 μs 0.0129 μs 0.0121 μs 4.394 μs 1.00 0.00 0.0153 10,115 B 440 B 1.00
Benchmark CoreRun CoreRun 5120 1 NoCompression 4.538 μs 0.0115 μs 0.0107 μs 4.539 μs 1.03 0.00 0.0153 12,422 B 440 B 1.00
Benchmark Baseline .NET 9.0 5120 1 SmallestSize 8.178 μs 0.0645 μs 0.0604 μs 8.200 μs 1.00 0.01 0.0153 10,114 B 440 B 1.00
Benchmark CoreRun CoreRun 5120 1 SmallestSize 8.232 μs 0.0368 μs 0.0307 μs 8.246 μs 1.01 0.01 0.0153 12,280 B 440 B 1.00
Benchmark Baseline .NET 9.0 5120 5 Optimal 32.948 μs 0.1738 μs 0.1626 μs 32.897 μs 1.00 0.01 - 10,341 B 760 B 1.00
Benchmark CoreRun CoreRun 5120 5 Optimal 31.612 μs 0.0787 μs 0.0736 μs 31.595 μs 0.96 0.01 - 13,046 B 440 B 0.58
Benchmark Baseline .NET 9.0 5120 5 Fastest 30.875 μs 0.0923 μs 0.0863 μs 30.891 μs 1.00 0.00 - 10,504 B 760 B 1.00
Benchmark CoreRun CoreRun 5120 5 Fastest 30.094 μs 0.0366 μs 0.0325 μs 30.090 μs 0.97 0.00 - 13,050 B 440 B 0.58
Benchmark Baseline .NET 9.0 5120 5 NoCompression 20.877 μs 0.2099 μs 0.1964 μs 20.951 μs 1.00 0.01 - 10,341 B 760 B 1.00
Benchmark CoreRun CoreRun 5120 5 NoCompression 19.600 μs 0.1155 μs 0.1081 μs 19.648 μs 0.94 0.01 - 13,023 B 440 B 0.58
Benchmark Baseline .NET 9.0 5120 5 SmallestSize 33.643 μs 0.0863 μs 0.0765 μs 33.640 μs 1.00 0.00 - 10,341 B 760 B 1.00
Benchmark CoreRun CoreRun 5120 5 SmallestSize 32.488 μs 0.0678 μs 0.0634 μs 32.460 μs 0.97 0.00 - 13,046 B 440 B 0.58
Benchmark Baseline .NET 9.0 5120 100 Optimal 614.423 μs 1.6393 μs 1.5334 μs 614.570 μs 1.00 0.00 - 10,341 B 8361 B 1.00
Benchmark CoreRun CoreRun 5120 100 Optimal 600.729 μs 1.1876 μs 1.1109 μs 600.486 μs 0.98 0.00 - 13,050 B 440 B 0.05
Benchmark Baseline .NET 9.0 5120 100 Fastest 608.128 μs 1.2270 μs 1.1477 μs 607.883 μs 1.00 0.00 - 10,302 B 8361 B 1.00
Benchmark CoreRun CoreRun 5120 100 Fastest 584.501 μs 1.4348 μs 1.3421 μs 584.326 μs 0.96 0.00 - 13,105 B 440 B 0.05
Benchmark Baseline .NET 9.0 5120 100 NoCompression 417.958 μs 1.4502 μs 1.3565 μs 417.628 μs 1.00 0.00 - 10,329 B 8360 B 1.00
Benchmark CoreRun CoreRun 5120 100 NoCompression 385.970 μs 0.9110 μs 0.8521 μs 385.769 μs 0.92 0.00 - 13,107 B 440 B 0.05
Benchmark Baseline .NET 9.0 5120 100 SmallestSize 657.179 μs 1.0635 μs 0.8881 μs 657.387 μs 1.00 0.00 - 10,302 B 8361 B 1.00
Benchmark CoreRun CoreRun 5120 100 SmallestSize 616.534 μs 1.1498 μs 1.0755 μs 616.422 μs 0.94 0.00 - 13,050 B 441 B 0.05
Benchmark Baseline .NET 9.0 5120 500 Optimal 3,196.052 μs 6.1542 μs 5.7566 μs 3,196.645 μs 1.00 0.00 - 10,764 B 40362 B 1.00
Benchmark CoreRun CoreRun 5120 500 Optimal 2,960.549 μs 20.2741 μs 18.9644 μs 2,970.971 μs 0.93 0.01 - 13,757 B 443 B 0.01
Benchmark Baseline .NET 9.0 5120 500 Fastest 3,059.133 μs 10.2080 μs 9.5486 μs 3,057.031 μs 1.00 0.00 - 10,711 B 40363 B 1.00
Benchmark CoreRun CoreRun 5120 500 Fastest 2,918.923 μs 6.2479 μs 5.5386 μs 2,917.097 μs 0.95 0.00 - 13,703 B 443 B 0.01
Benchmark Baseline .NET 9.0 5120 500 NoCompression 2,152.079 μs 1.8316 μs 1.5295 μs 2,151.759 μs 1.00 0.00 - 10,844 B 40363 B 1.00
Benchmark CoreRun CoreRun 5120 500 NoCompression 1,959.104 μs 4.8079 μs 4.4973 μs 1,959.550 μs 0.91 0.00 - 13,735 B 443 B 0.01
Benchmark Baseline .NET 9.0 5120 500 SmallestSize 3,268.836 μs 6.0249 μs 5.6357 μs 3,267.207 μs 1.00 0.00 - 10,851 B 40363 B 1.00
Benchmark CoreRun CoreRun 5120 500 SmallestSize 3,140.089 μs 5.5923 μs 4.9574 μs 3,139.895 μs 0.96 0.00 - 13,693 B 442 B 0.01
Benchmark Baseline .NET 9.0 5120 1000 Optimal 6,231.984 μs 12.2035 μs 10.1905 μs 6,230.243 μs 1.00 0.00 - 10,850 B 80364 B 1.000
Benchmark CoreRun CoreRun 5120 1000 Optimal 5,773.642 μs 23.5855 μs 22.0619 μs 5,769.059 μs 0.93 0.00 - 13,702 B 446 B 0.006
Benchmark Baseline .NET 9.0 5120 1000 Fastest 6,046.628 μs 6.9403 μs 5.7954 μs 6,047.235 μs 1.00 0.00 - 10,711 B 80366 B 1.000
Benchmark CoreRun CoreRun 5120 1000 Fastest 5,830.096 μs 11.0885 μs 9.2594 μs 5,830.927 μs 0.96 0.00 - 13,703 B 446 B 0.006
Benchmark Baseline .NET 9.0 5120 1000 NoCompression 4,368.783 μs 20.8749 μs 17.4315 μs 4,369.662 μs 1.00 0.01 - 10,790 B 80364 B 1.000
Benchmark CoreRun CoreRun 5120 1000 NoCompression 3,912.424 μs 51.6850 μs 48.3462 μs 3,889.387 μs 0.90 0.01 - 13,680 B 442 B 0.005
Benchmark Baseline .NET 9.0 5120 1000 SmallestSize 6,593.829 μs 26.7134 μs 24.9878 μs 6,595.973 μs 1.00 0.01 - 10,765 B 80366 B 1.000
Benchmark CoreRun CoreRun 5120 1000 SmallestSize 6,240.836 μs 13.6032 μs 12.7245 μs 6,243.574 μs 0.95 0.00 - 13,685 B 444 B 0.006

We'll also be able to revisit #71991, since one of the reasons for its partial reversion in #85001 was that the Inflater class would sometimes recreate its SafeHandle during its lifetime. This no longer happens.

I'd also appreciate it if someone could run the outer loop tests too - they contain the ManyManyConcatenatedGzipStreams test.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 16, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-io-compression
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me. Thanks.

Do we have sufficient test coverage of concatenated gzip streams to appropriately exercise this?

@edwardneal
Copy link
Contributor Author

Thanks. I think we do - GzipStreamUnitTests has the ConcatenatedGzipStreams, ConcatenatedEmptyGzipStreams, ManyConcatenatedGzipStreams and ManyManyConcatenatedGzipStreams tests. CompressionStreamUnitTestBase covers us for regressions against a single stream.

@edwardneal
Copy link
Contributor Author

edwardneal commented Mar 20, 2025

/azp run runtime-libraries-coreclr outerloop

Edit: could someone trigger the outerloop tests for ManyManyConcatenatedGzipStreams please?

@azure-pipelines

This comment was marked as resolved.

1 similar comment
@azure-pipelines

This comment was marked as resolved.

@stephentoub
Copy link
Member

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@edwardneal
Copy link
Contributor Author

Thanks. The GZip tests and the wider set of System.IO.Compression tests are passing on both pipelines. The remaining test failures look unrelated to me.

@carlossanlop
Copy link
Contributor

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@carlossanlop
Copy link
Contributor

/ba-g Deadletter in an unrelated test

Copy link
Contributor

@carlossanlop carlossanlop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'll make sure we mention this perf improvement in the next preview release notes.

@carlossanlop carlossanlop merged commit 9d2b23b into dotnet:main Apr 14, 2025
151 of 167 checks passed
@edwardneal edwardneal deleted the feat/zlib-reset-inflater branch April 14, 2025 17:42
@github-actions github-actions bot locked and limited conversation to collaborators May 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.IO.Compression community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants