valence-rs / valence

A Rust framework for building Minecraft servers.
http://valence.rs/
MIT License
2.7k stars 140 forks source link

Optimize `VarInt`/`VarLong` encode and decode procedures #208

Open rj00a opened 1 year ago

rj00a commented 1 year ago

Varints are prolific in the Minecraft protocol. It makes sense to try and optimize them as best as we can. The current implementation is straightforward but there is room for improvement.

See:

Benchmarks must be made with criterion to establish confidence.

rileysu commented 1 year ago

Would it increase performance just to unwrap the loop in this case? Other than that I am not sure how to convert the Read to a statically sized buffer that can deliver some of these performance improvements.

rj00a commented 1 year ago

We don't need to use Read. &mut &[u8] should be used instead.