Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4271

Replace Snappy and Zstd with managed implementations

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Unknown Unknown
    • 2.18.0
    • Affects Version/s: None
    • Component/s: None

      The .NET/C# Driver supports all 3 wire compression formats (Snappy, Zstd, and Zlib) implemented by the server. Zlib is implemented using SharpCompress, a fully managed library that supports any target platform supported by .NET. Snappy and Zstd are implemented using unmanaged libraries that must be compiled for every supported platform.

      We currently compile Snappy for x86/x64 Windows, x64 MacOS, and x64 Linux. We compile Zstd for x64 Windows, x64 MacOS, and x64 Linux. We do not compile either compression library for ARM64 on any operating system. Thus we cannot run natively on the Apple M1 CPU, which is an ARM64 chip. When running on .NET 5 or earlier, .NET applications run through Rosetta 2 on the Apple M1. .NET 6 includes native support for the Apple M1 and Snappy/Zstd compression will no longer work unless after upgrading to .NET 6 ARM64. (You can still run .NET 6 x64 via Rosetta 2.) See CSHARP-4101 for more information.

      Snappy and Zstd for Windows are not compiled with ASLR enabled, which is a security concern for some users. We have not undertaken the work to recompile these libraries with ASLR enabled. Managed dependencies essentially implement ASLR for free due to the nature of how the managed runtime loads dependencies.

      Recent improvements in managed performance including the introduction of Span<T> support have brought managed performance close to unmanaged levels even for CPU intensive operations such as compression. In our own benchmarks we achieved comparable or better performance than the unmanaged implementations of Snappy and Zstd. By switching to managed implementations of these libraries, we can simplify our driver and packaging thus allowing us to run without change on any platform supported by .NET. This would notably include ARM64 targets such as Apple M1, Windows ARM64, and Linux ARM64.

            adelin.mbidaowona@mongodb.com Adelin Mbida Owona
            james.kovacs@mongodb.com James Kovacs
            0 Vote for this issue
            1 Start watching this issue