**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)
When serializing and deserializing to/from JSON we need to explicitly write nulls.
Because for development/editing we need to differentiate the following cases:
1. JSON is of an older version (field missing) -> initialize with code defined default
2. JSON is of the current version and field is actually null -> initialize with null
For networking we don't need to differentiate between those cases since client and server have the same version of the code at runtime.
So in networking case we can omit nulls from the JSON and skip all of these:
```
"OnComponentDestroy": null,
"OnComponentDisabled": null,
"OnComponentEnabled": null,
"OnComponentFixedUpdate": null,
"OnComponentStart": null,
"OnComponentUpdate": null,
"OnPropBreak": null,
"OnPropTakeDamage": null,
```
However, this wont reduce the amount of data that ends up on the wire, because compression already does a good job at deduplicating those strings.
```
Raw JSON with nulls : 41Kb
Raw JSON skip nulls : 27Kb (13Kb saved, 33.6% smaller, 1.51x ratio)
LZ4 fast with nulls : 7Kb (34Kb saved, 81.9% smaller, 5.54x ratio)
LZ4 fast skip nulls : 7Kb (34Kb saved, 82.6% smaller, 5.76x ratio)
```
The main benefit instead comes from saving CPU resources as this makes compression/decompression faster, because there is less data to process.
```
LZ4 with nulls compress : 0.210 ms/op
LZ4 with nulls decomp : 0.232 ms/op
LZ4 skip nulls compress : 0.165 ms/op
LZ4 skip nulls decomp : 0.074 ms/op
```
* Can output network diagnostics to file in data/<game> folder, `net_diag_record 1` -> `net_diag_dump`
* Record Sync Vars
* Record per connection traffic
* Record incoming AND outgoing traffic
The host can detatch a networked object from networking - which is like network destroying it, except it stops networking and becomes a regular snapshot object (host can set NetworkMode to NetworkMode.Snapshot) even after its network spawned.
Added BlobData API which will serialize as a binary file blob.
> Useful for large data structure
```csharp
class MyBinaryData : BlobData
{
public override void Serialize( ref Writer writer )
{
writer.Stream.Write( 1337 );
}
public override void Deserialize( ref Reader reader )
{
int val = reader.Stream.Read<int>();
}
}
```
* Fixes GameObject references in GameObjectSystem NetLists and NetDictionaries being null on clients.
* dotnet format
---------
Co-authored-by: Andy <10728824+andy013@users.noreply.github.com>
* Stop generating solutions via -test flag add -generatesolution
* Add TestAppSystem remove Application.InitUnitTest
Avoids some hacks and also makes sure our tests are as close to a real AppSystem as possible.
* Add shutdown unit test
shuts down an re-inits the engine
* Properly dispose native resources hold by managed during shutdown
Should fix a bunch of crashes
* Fix filesystem and networking tests
* StandaloneTest does proper Game Close
* Make sure package tests clean up properly
* Make sure menu scene and resources are released on shutdown
* Report leaked scenes on shutdown
* Ensure DestroyImmediate is not used on scenes
* Fix unmounting in unit tests not clearing native refs
* Force destroy native resource on ResourceLib Clear