[CSHARP-4271] Replace Snappy and Zstd with managed implementations Created: 26/Jul/22  Updated: 09/Aug/22  Resolved: 09/Aug/22

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.18.0

Type: Improvement Priority: Unknown
Reporter: James Kovacs Assignee: Adelin Mbida Owona
Resolution: Done Votes: 0
Labels: compression, compressors
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CSHARP-2874 Improve Snappy dll loading and/or pac... Closed
related to CSHARP-3612 Installing the driver using NuGet pul... Closed
is related to CSHARP-4101 Update Snappy/Zstd to support M1 Closed
Epic Link: Use Managed Libraries for Compression

 Description   

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.



 Comments   
Comment by Githook User [ 09/Aug/22 ]

Author:

{'name': 'Adelin Owona', 'email': 'adelinowona@gmail.com', 'username': 'adelinowona'}

Message: CSHARP-4271: Replace Snappy and Zstd with managed implementations
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/cb45ab4af80c6e9ed9205ece8f6fb39505c40e4b

Generated at Wed Feb 07 21:47:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.