Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[relay] allow flatbuffer fast track + clean up #40

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

belettee
Copy link

This is the necessary PR to make stayintarkov/StayInTarkov.Client#271 work with TCP Relay.

That's a longer diff than I wanted but everything looked really shiny. Cleaned up in the following ways:

  • use an explicit state object per client connection instead of relying on packet payload to determine which client, current match, etc. the packet is about
  • never use var, use const if you can, otherwise use let
  • use Array.isArray instead of JSON.stringify + x[0] === '['
  • use .indexOf when possible

@belettee belettee changed the base branch from master to development April 21, 2024 01:20
paulov-t added a commit to stayintarkov/StayInTarkov.Client that referenced this pull request Apr 21, 2024
This uses a new method of (de)serializing player state packets. This has
been tested over ~15hours of real gameplay with 3 people. It works
out-of-the-box for UDP peer-to-peer but requires an update to the nodejs
server for TCP Relay
(stayintarkov/SIT.Aki-Server-Mod#40). It uses
FlatBuffers, which I embedded as source files in the project to avoid
adding a new DLL to the release.

See image below for numbers:
- A) shows the difference in time spent for a median frame.
- `SIT.PacketProcessing` measures time spent handling incoming pstate
packets. We go from **2.84ms to 0.05ms (-98%)** which makes sense
because for this particular packet, workload is mostly deserialization,
which we skip entirely with the new system.
- `SIT.SendPlayerState` measures time spent sending pstate packets.
Here, we go from **2.63ms to 1.52ms (-42%)** which makes sense since we
write directly to a buffer instead of creating temp objects to then
serialize them.

- B) is even more relevant, it compares network usage, processing time
relative to script frame time and GC allocation.
- Traffic is reduced by **2x to 4x** in general (here **from ~60kb/s to
~17kb/s**).
- GC alloc goes **from ~115kb to ~26kb (-77%)** for
`SIT.SendPlayerState` and **from ~190kb to ~4kb (-98%)** (!!) for
`SIT.PacketProcessing`
- script frame time is much smoother and reduced after this patch, we
can see a lot less spikes (due to slow `SIT.PacketProcessing` as shown
highlighted in light blue)


![playerstate-before-after](https://github.com/stayintarkov/StayInTarkov.Client/assets/87133271/f6020f33-b017-4d8b-a629-d4c15923b382)
@paulov-t paulov-t merged commit 4884fda into stayintarkov:development Apr 22, 2024
1 check passed
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.

2 participants