aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-03-18 16:28:46 -1030
committermat <git@matdoes.dev>2026-03-20 04:21:58 -0200
commit25cd1c0b60604655b70d70f8ec33a54853905eea (patch)
tree28911045f6d69b2fffcb8d9c5a92fe32657b5e4b /azalea-protocol
parentb03d2942e1bef98e13acadde5cbb8856a3f8c74d (diff)
downloadazalea-drasl-25cd1c0b60604655b70d70f8ec33a54853905eea.tar.xz
optimize pathfinder swarms and write perf guide
Diffstat (limited to 'azalea-protocol')
-rw-r--r--azalea-protocol/Cargo.toml7
-rw-r--r--azalea-protocol/benches/read.rs37
-rw-r--r--azalea-protocol/examples/handshake_proxy.rs4
-rw-r--r--azalea-protocol/src/packets/game/c_level_chunk_with_light.rs4
-rw-r--r--azalea-protocol/src/packets/game/c_light_update.rs6
5 files changed, 51 insertions, 7 deletions
diff --git a/azalea-protocol/Cargo.toml b/azalea-protocol/Cargo.toml
index 193e153e..3ae65416 100644
--- a/azalea-protocol/Cargo.toml
+++ b/azalea-protocol/Cargo.toml
@@ -7,9 +7,10 @@ license.workspace = true
repository.workspace = true
[dev-dependencies]
-anyhow.workspace = true
+eyre.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
+criterion.workspace = true
[dependencies]
azalea-auth.workspace = true
@@ -56,3 +57,7 @@ bevy_ecs = [
[lints]
workspace = true
+
+[[bench]]
+name = "read"
+harness = false
diff --git a/azalea-protocol/benches/read.rs b/azalea-protocol/benches/read.rs
new file mode 100644
index 00000000..ad309bbc
--- /dev/null
+++ b/azalea-protocol/benches/read.rs
@@ -0,0 +1,37 @@
+use std::{hint::black_box, io::Cursor};
+
+use azalea_buf::AzBuf;
+use azalea_core::position::Vec3i;
+use azalea_protocol::packets::game::{
+ ClientboundWaypoint,
+ c_waypoint::{
+ TrackedWaypoint, WaypointData, WaypointIcon, WaypointIdentifier, WaypointOperation,
+ },
+};
+use criterion::{Criterion, criterion_group, criterion_main};
+use uuid::Uuid;
+
+fn benchmark(c: &mut Criterion) {
+ c.bench_function("c_waypoint", |b| {
+ let mut buf = Vec::new();
+ ClientboundWaypoint {
+ operation: WaypointOperation::Update,
+ waypoint: TrackedWaypoint {
+ identifier: WaypointIdentifier::Uuid(Uuid::nil()),
+ icon: WaypointIcon {
+ style: "minecraft:default".into(),
+ color: None,
+ },
+ data: WaypointData::Vec3i(Vec3i { x: 1, y: 67, z: 0 }),
+ },
+ }
+ .azalea_write(&mut buf)
+ .unwrap();
+ b.iter(|| {
+ black_box(ClientboundWaypoint::azalea_read(&mut Cursor::new(&buf)).unwrap());
+ });
+ });
+}
+
+criterion_group!(benches, benchmark);
+criterion_main!(benches);
diff --git a/azalea-protocol/examples/handshake_proxy.rs b/azalea-protocol/examples/handshake_proxy.rs
index cfe4af52..0d04d526 100644
--- a/azalea-protocol/examples/handshake_proxy.rs
+++ b/azalea-protocol/examples/handshake_proxy.rs
@@ -49,7 +49,7 @@ const PROXY_PLAYERS: Players = Players {
const PROXY_SECURE_CHAT: Option<bool> = Some(false);
#[tokio::main]
-async fn main() -> anyhow::Result<()> {
+async fn main() -> eyre::Result<()> {
tracing_subscriber::fmt().with_max_level(Level::INFO).init();
// Bind to an address and port
@@ -64,7 +64,7 @@ async fn main() -> anyhow::Result<()> {
}
}
-async fn handle_connection(stream: TcpStream) -> anyhow::Result<()> {
+async fn handle_connection(stream: TcpStream) -> eyre::Result<()> {
stream.set_nodelay(true)?;
let ip = stream.peer_addr()?;
let mut conn: Connection<ServerboundHandshakePacket, ClientboundHandshakePacket> =
diff --git a/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs b/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs
index 00489513..83fadd0b 100644
--- a/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs
+++ b/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs
@@ -22,8 +22,8 @@ pub struct ClientboundLevelChunkPacketData {
pub heightmaps: Vec<(HeightmapKind, Box<[u64]>)>,
/// The raw chunk sections.
///
- /// We can't parse the data in azalea-protocol because it depends on context
- /// from other packets
+ /// We can't parse the data in `azalea-protocol` because sometimes we want
+ /// to skip parsing this.
///
/// This is an Arc because it's often very big and we want it to be cheap to
/// clone.
diff --git a/azalea-protocol/src/packets/game/c_light_update.rs b/azalea-protocol/src/packets/game/c_light_update.rs
index 83dbda34..1a7027ca 100644
--- a/azalea-protocol/src/packets/game/c_light_update.rs
+++ b/azalea-protocol/src/packets/game/c_light_update.rs
@@ -1,3 +1,5 @@
+use std::sync::Arc;
+
use azalea_buf::AzBuf;
use azalea_core::bitset::BitSet;
use azalea_protocol_macros::ClientboundGamePacket;
@@ -17,6 +19,6 @@ pub struct ClientboundLightUpdatePacketData {
pub block_y_mask: BitSet,
pub empty_sky_y_mask: BitSet,
pub empty_block_y_mask: BitSet,
- pub sky_updates: Vec<Vec<u8>>,
- pub block_updates: Vec<Vec<u8>>,
+ pub sky_updates: Arc<Box<[Box<[u8]>]>>,
+ pub block_updates: Arc<Box<[Box<[u8]>]>>,
}