valence/benchmarks
Ryan Johnson ae7eaf15fc
Big Optimizations (#164)
Closes #84

# Changes

- Implemented new algorithm for tracking loaded entities and chunks.
- The client does not need to maintain a list of loaded chunks and
entities anymore, as this information can be inferred using carefully
maintained data from the previous tick.
- Chunks are used as a spatial partition for entities. Entity visibility
is now based on chunk visibility rather than the euclidean distance to
clients.
- The BVH is no longer strictly necessary, so it has been moved to the
new `valence_spatial_index` crate.
- The API has been generalized to support things other than entities.
The crate does not have a dependency on the main `valence` crate.
- Chunk, entity, and player list packets are now aggressively cached to
increase performance.
- Chunk packets now include some filler light data. This makes the
vanilla client lag a lot less.
- Entities and chunks must now be marked as deleted before they are
removed.
- Improved `ChunkPos` interface.
- Added function to get the duration per tick.
- Added `Index` and `IndexMut` impls to collection types.

As a result of the above changes, performance under heavy load has
increased significantly. With the rust-mc-bot test on my machine, I went
from a max of ~1000 players to ~4000 players.
2022-12-11 02:37:02 -08:00
..
bench_players Big Optimizations (#164) 2022-12-11 02:37:02 -08:00
README.md Optimize sending tracked entity data (#163) 2022-11-30 15:55:46 -08:00

Performance Tests

Run the server

cargo r -r -p bench_players

In a separate terminal, start rust-mc-bot. This command should connect 1000 clients to the server.

# In the rust-mc-bot directory
cargo r -r -- 127.0.0.1:25565 1000

If the delta time is consistently >50ms, the server is running behind schedule.

Note:

Flamegraph

To start capturing a flamegraph, run the server like this:

# You can also try setting the `CARGO_PROFILE_RELEASE_DEBUG` environment variable to `true`.
cargo flamegraph -p bench_players

Run rust-mc-bot as above, and then stop the server after a few seconds. Flamegraph will generate a flamegraph.svg in the current directory. You can then open that file in your internet browser of choice.