Skip to content

Add ZXC compression codec#120662

Open
hellobertrand wants to merge 2 commits into
godotengine:masterfrom
hellobertrand:add-zxc-compression-codec
Open

Add ZXC compression codec#120662
hellobertrand wants to merge 2 commits into
godotengine:masterfrom
hellobertrand:add-zxc-compression-codec

Conversation

@hellobertrand

@hellobertrand hellobertrand commented Jun 26, 2026

Copy link
Copy Markdown

What problem(s) does this PR solve?

Adds ZXC as a new optional compression format, alongside FastLZ, Deflate, Zstandard, gzip and Brotli. ZXC is an asymmetric LZ codec (BSD-3-Clause), optimized for very fast decompression. That fits the engine's "compress once, decompress many times at load" pattern. Full rationale is in the proposal.

Disclosure: I'm the author/maintainer of the ZXC library.

Additional information

  • Compression::MODE_ZXC with full compress / decompress / get_max_compressed_buffer_size.
  • Exposed to scripting as FileAccess.COMPRESSION_ZXC, works from PackedByteArray.compress() / decompress() and FileAccess.open_compressed().
  • Project setting compression/formats/zxc/compression_level (range 1-6, default 3).
  • Build options zxc and builtin_zxc, gated by the ZXC_ENABLED define. zxc=no builds cleanly.
  • ZXC's runtime SIMD dispatch wired into SCons: zxc_compress.c / zxc_decompress.c / zxc_huffman.c are compiled once per ISA variant (sse2/avx2/avx512 on x86_64, neon on ARM) and selected at runtime via CPUID/getauxval. No -march=native, single portable binary.
  • Library bundled under thirdparty/zxc/ (v0.12.0), documented in thirdparty/README.md and COPYRIGHT.txt (BSD-3-Clause, plus vendored rapidhash under Expat/MIT).
  • Class reference updates (FileAccess.xml, ProjectSettings.xml) and round-trip unit tests.

Benchmark

Standalone harness mirroring the exact Compression calls (zstd level 3, fastlz, zxc). Apple M3, clang -O3, single-threaded, zstd 1.5.7, zxc 0.12.0 (NEON path selected at runtime). Throughput in MB/s (decimal). Every row round-trips.

Structured text doc/classes/*.xml (8.3 MB)

codec ratio comp MB/s decomp MB/s
zstd-3 (engine default) 6.24x 251 948
fastlz 3.75x 256 414
zxc-1 2.82x 237 3139
zxc-3 (default) 4.23x 89 1764
zxc-6 5.48x 3.9 1814

Low-compressibility binary, editor-binary slice (25 MB)

codec ratio comp MB/s decomp MB/s
zstd-3 3.05x 142 431
fastlz 1.89x 121 262
zxc-1 1.45x 316 4936
zxc-3 2.11x 55 2398
zxc-6 2.36x 5.8 2549

The win is decode speed: zxc-3 is 2x faster than zstd-3 and 4x faster than fastlz. It's a strong FastLZ replacement: better ratio and decode speed. It does not beat Zstandard on ratio or compression speed. Useful range is L1-L5.

Real-world load (Godot engine path)

Loading a serialized PackedScene (16k-node level, 1.71 MB) through the engine, optimized editor build (dev_build=no optimize=speed), Apple M3:

codec comp. size ratio in-memory decode engine load (open_compressed)
fastlz 740 KB 2.31x 1.183 ms 1.430 ms
zstd-3 261 KB 6.55x 0.794 ms 1.073 ms
zxc-3 574 KB 2.98x 0.167 ms 0.485 ms

ZXC decodes the scene 4.7x faster than zstd-3 in pure decode, 2.2x faster through the full FileAccessCompressed path. The trade-off: zstd's output is 2.2x smaller. So on slow / cold storage where I/O dominates, the smaller file narrows the gap. ZXC's advantage is largest when data is cached or storage is fast.

Integrates the ZXC library as a new, optional compression format.

This includes:
- New build options to enable/disable ZXC and its built-in library.
- Build system integration with CPU architecture-specific SIMD optimizations (SSE2, AVX2, AVX512, NEON) for core compression/decompression functions.
- API exposure in `Compression` and `FileAccess` classes.
- A new project setting for ZXC compression level.
- Documentation updates and round-trip tests.
- Inclusion of the `zxc` third-party library (BSD-3-clause) and its `rapidhash` dependency (Expat).
@hellobertrand hellobertrand marked this pull request as ready for review June 26, 2026 17:11
@hellobertrand hellobertrand requested review from a team as code owners June 26, 2026 17:11
@Calinou Calinou added this to the 4.x milestone Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ZXC compression codec

2 participants