Files
sbox-public/engine/Sandbox.Engine/Protocol.cs
Lorenz Junglas 519ad5d815 Network: Broadcast and Chunking compression optimization (#4417)
**Broadcast**
now encodes the wire payload just once and sends the same bytes to
every recipient, before we did one redundant compression per connection.
This primarily reduces CPU load on the server/host.

**Chunking**
Large messages are now compressed before chunking rather than after.
Resulting in slightly smaller payloads.
The receiver now decompresses a single reassembled payload instead of
decompressing every chunk independently, significantly reducing CPU load
on receiving clients.

**Refactor**
Chunking and compression are now low-level wire concerns handled by
Connection rather than being mixed into the high-level message types.
The old `InternalMessageType.Chunk` enum is removed; chunk framing uses
a dedicated wire flag byte alongside `FlagRaw` and `FlagCompressed`.

**Results (Chunking changes)**

Synthetic data, results on real payloads may differ.

Benchmarks (1000 GOs / 2000 components, ~1MB payload, 500 iterations):

Wire size (chunk-first-then-compress):    275KB
Wire size (compress-first):               259KB  (5.7% smaller)

Send  chunk-first:                        0.85 ms/op  (old)
Send  compress-first:                     0.88 ms/op  (new)

Recv  chunk-first:                        1.16 ms/op  (old)
Recv  compress-first:                     0.34 ms/op  (new, 3.4x faster)
2026-03-31 11:56:17 +01:00

43 lines
1.4 KiB
C#

namespace Sandbox.Engine;
/// <summary>
/// A centralized place to access the protocols
/// </summary>
public static class Protocol
{
/// <summary>
/// We cannot play packages with an Api version higher than this.
/// </summary>
public static int Api => 25;
/// <summary>
/// We cannot talk to servers or clients with a network protocol different to this.
/// </summary>
public static int Network => 1100;
}
// Api Versions
// 25. 27 March 2026 - Shadows 2
// 24. 21 January 2026 - Weekly update
// 21. 12 July 2025 - Monthly update
// 20. 01 July 2025 - Monthly update
// 19. 06 May 2025 - New prefabs
// 18. 10 Mar 2025 - First staging version
// Network Versions
// 1100. 30th March 2026 - Compress-before-chunk, chunking moved to wire layer
// 1099. 24th Feburary 2026 - ResourceId is now a long
// 1098. 20th Feburary 2026 - Send network time as double
// 1097. 13rd January 2026 - Support for binary blobs
// 1096. 05th December 2025 - NetworkFlags + Transform Sync Flags
// 1095. 23rd November 2025 - Snapshot parent salt
// 1094. 10th November 2025 - Network visibility
// 1093. 13th October 2025 - LZ4 compression
// 1092. 1st October 2025 - Networking optimizations
// 1091. 5th Sept 2025 - FastHash changes
// 1090. 12th August - Delta snapshot changes
// 1087. 14 May 2025 - GameObject (reference) ByteReader/Writer improvements
// 1086. 8 May 2025 - Server time changed to double
// 1085. 10 Mar 2025 - First staging version