Commit Graph

23 Commits

Author SHA1 Message Date
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
Lorenz Junglas
238425e6d3 Omit nulls when serializing for network (#4376)
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
```
2026-03-27 10:59:06 +01:00
Jusvit
0d95cc9f53 Validate CanRefreshObjects for new network refresh messages 2026-03-25 16:00:08 +00:00
Tony Ferguson
d85a25686c Network Diagnostic Additions (#4358)
* 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
2026-03-20 16:59:51 +00:00
Conna Wiles
6262249de1 Time/RealTime.NowDouble (#4090) 2026-02-22 14:56:54 +00:00
Matt Stevens
8f859f0d57 Revert "Run Steam Callbacks in Network Thread (#3984)"
This reverts commit 848580f804.
2026-02-04 15:36:30 +00:00
Conna Wiles
848580f804 Run Steam Callbacks in Network Thread (#3984) 2026-02-03 15:40:34 +00:00
Conna Wiles
b3920fc8a1 Fix an issue where if a GameObjectSystem type doesn't exist on the client (older version) then it won't error when connecting to a server (#3922) 2026-01-28 11:29:45 +00:00
Conna Wiles
409e519d31 Network Detach (#3905)
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.
2026-01-27 21:02:03 +01:00
Conna Wiles
3f0c69a2ea CodeGen Lambda Cache + More Network Optimizations (#3893) 2026-01-27 16:41:18 +00:00
Antoine Pilote
36aa2a9f23 BlobDataSerializer is now stack based 2026-01-26 07:30:45 -08:00
sboxbot
4896eece62 Restrict client object destroying option (Networking) (#3816) 2026-01-19 15:35:13 +00:00
Antoine Pilote
d28a62c1f3 BinarySerializable (#3725)
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>();
    }
}
```
2026-01-15 05:57:30 -08:00
Conna Wiles
e657d878a6 Scene Change Improvements (#3740) 2026-01-13 13:43:58 +00:00
Conna Wiles
4740aeae6d CodeGenerator Improvements (#3738) 2026-01-12 17:34:41 +00:00
Conna Wiles
06222ffdc4 INetworkSnapshot Support for GameObjectSystem (#3743) 2026-01-12 16:01:53 +00:00
Andy
c3994087f9 Prevent INetworkListener OnDisconnected being called on clients 2025-12-13 13:41:36 +00:00
sboxbot
d3c9e389d0 Fix GameObjects in GameObjectSystem NetLists being null on clients (#3613)
* Fixes GameObject references in GameObjectSystem NetLists and NetDictionaries being null on clients.

* dotnet format

---------

Co-authored-by: Andy <10728824+andy013@users.noreply.github.com>
2025-12-12 13:39:40 +00:00
Andy
62c7df605d Call SceneLoaded listeners for clients 2025-12-12 13:39:00 +00:00
Lorenz Junglas
6808d8768e Shutdown fixes (#3553)
* 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
2025-12-08 15:55:11 +01:00
Lorenz Junglas
9551e9844e Cache (De)SerializeOptions in hot paths (#3547)
They are essentially compile time constants, so we shouldn't allocate them
2025-12-03 19:36:51 +00:00
Conna Wiles
af0204fc15 Connection Input / User Commands (#3446) 2025-12-01 14:55:57 +00:00
s&box team
71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00