Refactor replication to use a buffer cache#42
Closed
UkoeHB wants to merge 1 commit intosimgine:masterfrom
Closed
Conversation
8837099 to
0bb7817
Compare
Codecov ReportPatch coverage:
❗ 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
☔ View full report in Codecov by Sentry. |
09d9a78 to
f4e6b13
Compare
Collaborator
Author
|
Rebased onto the updated benches. Replicating a |
UkoeHB
commented
Sep 20, 2023
f4e6b13 to
9ba3808
Compare
9ba3808 to
71e8d8b
Compare
Contributor
|
Superseded by #46. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.