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

Optimize world diff collection #32

Closed
UkoeHB opened this issue Aug 9, 2023 · 2 comments
Closed

Optimize world diff collection #32

UkoeHB opened this issue Aug 9, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@UkoeHB
Copy link
Collaborator

UkoeHB commented Aug 9, 2023

Problem

World diff collection involves:

  • iterating over all replicated entities and their replicated components to identify which components need to be sent to clients
  • allocating intermediary 'world diffs' for each client, which contain all the diffs they will be sent this tick

Solution

The first problem can be mitigated with per-entity change detection, so you don't need to iterate over components in entities that haven't changed in a while.

Here are three ideas to mitigate the second problem (as discussed on discord).

  1. Serialize diffs directly into per-client buffers instead of allocating intermediary representations. Easy to implement, fast. Can work with diff fragmentation by allocating a new buffer representing a new packet whenever the current buffer is packed (with some byte shuffling to manage entity boundaries).
  2. Build a world diff history cache that has per-tick diffs for replicated entities (only most recent changes are cached). Client packets are built by directly serializing into buffers from the diff cache. Moderate difficulty to implement, faster than current code but slower than (1) because the cache must be allocated. Also supports diff fragmentation.
  3. Bundle-based replication using auto-generated systems to collect diffs. Hard to implement, equivalent to (1). Also supports diff fragmentation.

In conclusion, (1) seems like a safe bet.

@Shatur
Copy link
Contributor

Shatur commented Aug 9, 2023

bevyengine/bevy#5097 should also speedup iteration.

@Shatur Shatur added the enhancement New feature or request label Aug 9, 2023
@Shatur
Copy link
Contributor

Shatur commented Sep 22, 2023

Closed by #46.

@Shatur Shatur closed this as completed Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants