Skip to content

Comments

Refactor replication to use a buffer cache#42

Closed
UkoeHB wants to merge 1 commit intosimgine:masterfrom
UkoeHB:speedy_replication
Closed

Refactor replication to use a buffer cache#42
UkoeHB wants to merge 1 commit intosimgine:masterfrom
UkoeHB:speedy_replication

Conversation

@UkoeHB
Copy link
Collaborator

@UkoeHB UkoeHB commented Sep 20, 2023

Problem

When servers build a replication diff, they allocate many times to collect an intermediate representation of the message. This is quite inefficient.

Solution

Use a buffer for the intermediate representation so allocations are greatly reduced. We still have allocations when new entities are introduced.

I saw a 40% speedup in the 'entities send' benchmark, and 6% in the 'entities receive' benchmark. I did not examine packet sizes, although I expect them to be smaller due to some optimizations around entity and replication ids.

This PR depends on #41.

Follow-up

The replication buffer should have a queue of ComponentDatas collected from despawned entities for reuse with new entities. In that case the long-run upper limit on buffer size will be: O(max entities * max entity size).

The buffer currently limits apps to 65k replicable entities and 127 replicable components per entity. It may be possible to configure those values at compile time.

Entities can be serialized as two u32 varints instead of a u64 varint, which should save 1-3 bytes per entity since entities are actually two u32s concatenated.

@UkoeHB UkoeHB force-pushed the speedy_replication branch 4 times, most recently from 8837099 to 0bb7817 Compare September 20, 2023 17:37
@codecov-commenter
Copy link

codecov-commenter commented Sep 20, 2023

Codecov Report

Patch coverage: 96.95% and project coverage change: -0.17% ⚠️

Comparison is base (cbc6825) 95.47% compared to head (0bb7817) 95.31%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #42      +/-   ##
==========================================
- Coverage   95.47%   95.31%   -0.17%     
==========================================
  Files          10       10              
  Lines         663      725      +62     
==========================================
+ Hits          633      691      +58     
- Misses         30       34       +4     
Files Changed Coverage Δ
src/replicon_core.rs 96.00% <96.58%> (-0.30%) ⬇️
src/server.rs 95.80% <97.82%> (-0.67%) ⬇️
src/client.rs 84.74% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@UkoeHB UkoeHB force-pushed the speedy_replication branch 2 times, most recently from 09d9a78 to f4e6b13 Compare September 20, 2023 21:04
@UkoeHB
Copy link
Collaborator Author

UkoeHB commented Sep 20, 2023

Rebased onto the updated benches. Replicating a DummyComponent(usize) now instead of DummyComponent, so the perf gain from this PR is only 20% for entity creation. However it is 50% faster for updating components (and for some reason the client-side is 45% faster for updating components).

@Shatur
Copy link
Contributor

Shatur commented Sep 22, 2023

Superseded by #46.

@Shatur Shatur closed this Sep 22, 2023
@UkoeHB UkoeHB deleted the speedy_replication branch September 22, 2023 12:18
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.

3 participants