Skip to content

Plan to migrate to zlib-ng #101465

Closed
Closed
@carlossanlop

Description

@carlossanlop

For .NET 9, we are planning to replace our dependency of madler/zlib and zlib-intel with a dependency to zlib-ng.

The zlib-ng repo offers an alternative implementation of the zlib algorithm that:

  • Is compatible and optimized for next-generation platforms and architectures.
  • Adopted the known zlib-intel and Cloudflare optimizations.
  • Deleted old and obsolete code.
  • Adopted all known CVE fixes.
  • Is actively maintained by multiple people and has a quick turnaround for fixing security issues. Additionally, zlib-intel is out of support already.

Acceptance criteria

Tests

  • All tests must continue to pass, especially tests that read data.
  • If needed, adjust tests that measure specific output characteristics of compression, but they must pass.
  • Inputs which do not yield an Exception must continue to be Exception-free.
  • Add unmanaged tests to directly verify the p/invoked methods.

Threat modeling

  • Have a threat modeling exercise and make adjustments to the code if needed. Do this before collecting performance results.

Elapsed time

  • Elapsed time for optimal compression should not increase more than 10%. "Optimal" should be deferred to the library's inherent notion of default. If the increase is higher than 10%, we should discuss if we need to choose a less agressive value manually to keep results aligned with the previous version.
  • Elapsed time for fastest, smallest, and no-compression have no acceptance criteria, as they're entirely at the mercy of the underlying library. We may still collect and compare results.
  • Elapsed time for optimal decompression should also be verified, but no acceptance target is defined, as very little managed code is involved in the decompression stage, and there are no algorithmic choices to be had. But the measurements can help us determine if we need to invest in zlib-ng's performance.

Output size

  • Output size for optimal compression should not increase more than 10%, priority given to inclusive time. If the number differs due to the optimal compression being faster than baseline, then we need to decide if we should use a new manual value for optimal instead of deferring to the library default.

Managed memory

  • Managed allocations should not increase when compared to madler/zlib or zlib-intel.

Unmanaged memory

  • Peak unmanaged memory must be collected before and after. An acceptance criteria may be decided after comparing results, if needed.
  • Test for unmanaged memory leaks. If any are found, fix locally, then contribute upstream if applicable.

Servicing plan

  • No more than one release of .NET misses a given patch-release of zlib-ng. This takes in consideration the fact that zlib-ng does not have a predictable release cadence.
  • .NET moves to a newer major or minor version of zlib-ng within 3 months of the first patch-release or 6 months of the initial release, whichever is earlier. This aligns with zlib-ng's history of maintaining parallel version support.
  • zlib-ng takes security fixes as public PRs. There's a lag between accepting a fix and releasing it. We must be quick and reliably in taking patch commits, in addition to staying current on releases.
  • Any team member can update to a newer version of zlib-ng in less than 10 minutes.
    • Must test and document the updating process prior to releasing .NET 9.
    • Decide what the quick process will be and implement it, for example, writing a script.

Execution plan

Milestone 1: Migration

Milestone 2: Testing

  • 3 days - Run existing tests, ensure they pass.
  • 1 day - Verify correct results in all supported architectures and platforms in our CI.

Milestone 3: Performance

  • 2 weeks - Collect performance reports for before and after in Windows, Linux and MacOS, in x86, x64 and arm64 (Discuss if more configurations are needed). Compare results and discuss if action needs to be taken with the default values.

Milestone 4: Documentation

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions