Skip to content

perf: replace libdeflate with ISA-L; StepCache and archives on built-in zstd - #2793

Merged
kamronbatman merged 1 commit into
mainfrom
kb/replace_libdeflate
Nov 22, 2026
Merged

kamronbatman merged 1 commit into
mainfrom
kb/replace_libdeflate

Conversation

@kamronbatman

@kamronbatman kamronbatman commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Wire compression (gump 0xDD, house design 0xD8) and UOP reads now use IGzip.Bindings (Intel ISA-L) instead of LibDeflate.Bindings. Output stays zlib-framed, so clients are unaffected.
  • StepCache format v10: each chunk record is a zstd L19 frame compressed against a 64 KB dictionary. The writer trains the dictionary on every 7th record and stores it after the header. v9 .swb files are treated as missing and re-baked once.
  • ManagedArchive uses .NET 11's ZstandardStream; the ZstdNet package is removed.
  • CI, the BuildTool prerequisite checker, the README and platform-prerequisites.md now list libisal2 (apt) / isa-l (dnf, apk). IGzip bundles natives for win-x64 and osx-arm64, so only Intel Macs need brew install isa-l.
  • ClothingRaceTests is removed: it did not compile (missing usings).

Benchmarks

All numbers are BenchmarkDotNet runs pinned to one core on Windows x64. Compression time is per call.

Wire compression: libdeflate L6 (old default) vs ISA-L L1 (new)

Payload libdeflate L6 ISA-L L1 Size, libdeflate L6 → ISA-L L1
Gump layout 30.7 µs 8.1 µs 1,087 → 1,273 B
Gump text 19.2 µs 6.4 µs 760 → 812 B
Gump send (layout + text) 49.8 µs 14.5 µs 1,847 → 2,084 B (+13%)
Huge gump 208.6 µs 41.3 µs 6,471 → 7,848 B
House plane 6.94 µs 2.08 µs 108 → 124 B

Compression runs on the game loop for every send, so a gump send costs ~3.4x less loop time for ~13% more bytes.

Other encoders on the gump send (layout + text):

Encoder Time Size
libdeflate L1 26.7 µs 2,024 B
zlib-ng L2 (.NET 11 ZLibEncoder) 45.3 µs 2,062 B

Every zlib-ng level was beaten on both time and size by some libdeflate level. Levels 2–3 of ISA-L barely shrink the output and L3 doubles the time.

Against the zlib that RunUO and ServUO ship

RunUO (zlib 1.2.3) and ServUO (zlib 1.2.11) both compress gumps on the game thread with compress2 at the default level (6). House designs go to a background thread. Same payloads and pinned core as above, in one run:

Payload RunUO zlib 1.2.3 ServUO zlib 1.2.11 libdeflate L6 ISA-L L1
Gump send (layout + text) 129.5 µs 114.1 µs 52.0 µs 15.3 µs
Huge gump 706 µs 584 µs 256 µs 46.5 µs
House plane 15.2 µs 11.8 µs 9.7 µs 2.5 µs
Gump send size 1,886 B 1,886 B 1,847 B 2,084 B

ISA-L compresses a gump send ~7.5x faster than ServUO and ~8.5x faster than RunUO, for ~10% more bytes. Compressing a house plane on the game thread now costs less than the background-thread compression in either.

Decompression (load-time: UOP multis; tests: gumps)

Set libdeflate ISA-L
MultiUOP 2,137 ns 1,996 ns
Gump (large) 5,905 ns 6,364 ns
House plane 980 ns 950 ns

Within about 10% either way.

StepCache (map 0: 114,688 records, 117.3 MiB raw)

Codec Payload Bake (single thread) Read all
libdeflate L12 (v9) 15.78 MiB 59.7 s 0.220 s
zstd L19, no dictionary 16.42 MiB 66.1 s 0.208 s
zstd L19 + trained dictionary (v10) 15.70 MiB 32.1 s 0.169 s

Training the dictionary adds 0.5 s to the bake. Each record is only 256 cells, so most of the redundancy is between records. A dictionary captures that while still letting each chunk be read on its own, which is why the earlier dictionary-free zstd spike lost to libdeflate.

Archives: ZstdNet vs built-in ZstandardStream (31.6 MiB tar of a world save)

Level ZstdNet Built-in Size (both)
L3 80 ms 79 ms 5.94 MiB
L9 437 ms 440 ms 5.36 MiB
L19 9.44 s 9.83 s 4.63 MiB

Both libraries wrap libzstd 1.5.7, so the output is byte-for-byte the same size. Archives made by either one decompress with the other, so existing .tar.zst backups still extract.

Linux packages

libisal.so.2 checked with Docker on every image in the CI matrix: Ubuntu 22/26 and Debian 12/13 (libisal2, ISA-L 2.30–2.31), Fedora 44 (isa-l 2.32.1), CentOS Stream 9/10 and AlmaLinux 10 (isa-l 2.32.1 from EPEL). IGzip.Bindings' own CI covers Ubuntu 24, Alpine and Arch, plus the struct layout across 2.28–2.32.1.

Test plan

  • Server.Tests 1105/1105, UOContent.Tests 1370/1370 locally
  • New StepCache test: a 1024-chunk set trains a dictionary and every chunk round-trips
  • Version gate rejects v9 files
  • CI matrix (macOS now relies on the bundled osx-arm64 dylib)

…in zstd

- Wire compression and UOP reads use IGzip.Bindings (ISA-L) instead of
  LibDeflate.Bindings.
- StepCache format v10: each record is a zstd L19 frame compressed against a
  64 KB dictionary trained on every 7th record and stored after the header.
  Map 0: 15.70 MiB vs 15.78 (libdeflate L12), bake 32s vs 60s, reads ~25%
  faster. v9 files are re-baked once.
- ManagedArchive uses System.IO.Compression.ZstandardStream; ZstdNet removed.
  Same libzstd 1.5.7: identical output and speed, existing .tar.zst backups
  still extract.
- CI, BuildTool prerequisite checker and docs install libisal2 (apt) /
  isa-l (dnf, apk); macOS needs brew isa-l only on Intel, Apple Silicon uses
  the bundled copy.
- Remove ClothingRaceTests, which did not compile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kamronbatman
kamronbatman merged commit 9e56895 into main Nov 22, 2026
12 checks passed
@kamronbatman
kamronbatman deleted the kb/replace_libdeflate branch November 22, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant