From 2756eb419af2210eed3d0574e20a620918e4e577 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 22 Feb 2026 11:35:41 +0700 Subject: optimizations at high entity counts --- azalea-client/src/plugins/packet/mod.rs | 50 +++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'azalea-client/src/plugins/packet/mod.rs') diff --git a/azalea-client/src/plugins/packet/mod.rs b/azalea-client/src/plugins/packet/mod.rs index 63a94ee0..4309850e 100644 --- a/azalea-client/src/plugins/packet/mod.rs +++ b/azalea-client/src/plugins/packet/mod.rs @@ -11,6 +11,7 @@ use crate::chat::ChatReceivedEvent; pub mod config; pub mod game; pub mod login; +pub mod relative_updates; pub struct PacketPlugin; @@ -30,23 +31,27 @@ pub fn death_event_on_0_health( impl Plugin for PacketPlugin { fn build(&self, app: &mut App) { - app.add_observer(game::handle_outgoing_packets_observer) - .add_observer(config::handle_outgoing_packets_observer) - .add_observer(login::handle_outgoing_packets_observer) - .add_systems(Update, death_event_on_0_health) - .add_message::() - .add_message::() - .add_message::() - // - .add_message::() - .add_message::() - .add_message::() - .add_message::() - .add_message::() - .add_message::() - .add_message::() - .add_message::() - .add_message::(); + app.add_systems( + Update, + relative_updates::debug_detect_updates_received_on_local_entities, + ) + .add_observer(game::handle_outgoing_packets_observer) + .add_observer(config::handle_outgoing_packets_observer) + .add_observer(login::handle_outgoing_packets_observer) + .add_systems(Update, death_event_on_0_health) + .add_message::() + .add_message::() + .add_message::() + // + .add_message::() + .add_message::() + .add_message::() + .add_message::() + .add_message::() + .add_message::() + .add_message::() + .add_message::() + .add_message::(); } } @@ -70,12 +75,21 @@ macro_rules! __declare_packet_handlers { pub(crate) use __declare_packet_handlers as declare_packet_handlers; +#[derive(Resource)] +struct CachedSystemState(SystemState); + pub(crate) fn as_system(ecs: &mut World, f: impl FnOnce(T::Item<'_, '_>)) where T: SystemParam + 'static, { - let mut system_state = SystemState::::new(ecs); + // creating a new SystemState is expensive, so we save them as a Resource in the + // ecs + let mut system_state = match ecs.remove_resource::>() { + Some(s) => s.0, + None => SystemState::::new(ecs), + }; let values = system_state.get_mut(ecs); f(values); system_state.apply(ecs); + ecs.insert_resource(CachedSystemState(system_state)); } -- cgit v1.2.3