mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-03 01:09:29 -04:00
**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)
23 lines
717 B
C#
23 lines
717 B
C#
namespace Sandbox.Network;
|
|
|
|
/// <summary>
|
|
/// An empty connection that can be used for testing and optimizing processing.
|
|
/// Messages can not actually be sent to it, and it won't receive any either. Other clients
|
|
/// will be unaware of it.
|
|
/// </summary>
|
|
internal class EmptyConnection : Connection
|
|
{
|
|
public override string Address => "empty";
|
|
public override string Name => "empty";
|
|
public override bool IsHost => false;
|
|
|
|
internal override void InternalClose( int closeCode, string closeReason ) { }
|
|
internal override void InternalRecv( NetworkSystem.MessageHandler handler ) { }
|
|
internal override void InternalSend( byte[] data, NetFlags flags ) { }
|
|
|
|
public EmptyConnection( Guid id )
|
|
{
|
|
Id = id;
|
|
}
|
|
}
|