Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize zlib #38

Merged
merged 21 commits into from
Oct 2, 2024
Merged

Modernize zlib #38

merged 21 commits into from
Oct 2, 2024

Conversation

seionmoya
Copy link
Collaborator

@seionmoya seionmoya commented Sep 24, 2024

Background

.NET has it's own implementation of ZlibStream, but it's only available since .NET 6. It uses P/Invoke-ed Intels variant of zlib. Since this won't be usable within EFT, there are a variety of C# managed zlib libraries out there that we could. Here is a quick overview of the situation:

  • All of github libraries originate from ComponentAce.Compression.Libs.zlib
  • Elskom/zlib.managed:1.1.4.0 contains fixes to the above and is the most up to date.
  • Elskom/zlib.managed:main is the most modernized, throws and exception when deflating (System.InvalidOperationException in Deflate.Compress Elskom/zlib.managed#182)
  • bsg.componentace.compression.libs.zlib uses ArrayPool and Microsoft.Extensions.ObjectPool
  • SixLabors/ZlibStream:main refactored the codebase but is WIP
  • Every other library is an outdated fork of ComponentAce.Compressions.Libs.zlib

Currently we are using Elskom/zlib.managed:1.1.4.0, but there is plenty of room to improve the codebase. Due to compatability constraints of EFT's implementation of zlib, I believe the best option here is to modernize our implementation of zlib.

Goals

  • Port the functional parts from Elskom/zlib.managed:main
  • Improve code readability using SixLabors/ZlibStream:main as inspiration
  • Implement stream pools for zlibstream where applicable
  • If possible, make it a drop-in replacement of bsg.componentace.compression.libs.zlib to improve EFT's performance

Changes

  • Using Span<T>, ReadOnlySpan<T>
  • Added SimpleZlib (a wrapper around MemoryZlib)
  • Moved ZOutputStream from ComponentAce.Compression.Libs.Zlib to Elskom.Generic.Libs
  • Changed Fuyu.Common.Compression.Zlib to MemoryZlib, moved to Zlib.Managed
  • Changed Fuyu.Common.Compression.ZlibCompression to CompressionLevel, moved to Zlib.Managed
  • Changed Deflate.ConfigTable to Dictionary<CompressionLevel, Config>
  • Changed some constants to enums
  • Removed elskom code signing (EFT doesn't use it)
  • Removed unused classes from Elskom.Generic.Libs (not used internally)

@seionmoya seionmoya added the backend Related to Fuyu.Backend label Sep 24, 2024
@seionmoya seionmoya self-assigned this Sep 24, 2024
@seionmoya seionmoya added the enhancement New feature or request label Sep 24, 2024
Lacyway
Lacyway previously approved these changes Sep 24, 2024
@seionmoya seionmoya changed the title WIP: modernize zlib Modernize zlib Oct 2, 2024
@seionmoya seionmoya merged commit cc51ca8 into project-fika:main Oct 2, 2024
1 check passed
@seionmoya seionmoya deleted the modernize-zlib branch October 2, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Related to Fuyu.Backend enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants