From 88781007b0644e08e813a2f347cebeb76d80b4fe Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Tue, 14 Jul 2020 23:56:49 -0700 Subject: [PATCH] ecs: slightly improve perf with inlining changes --- crates/bevy_ecs/hecs/src/archetype.rs | 1 + crates/bevy_ecs/hecs/src/query.rs | 6 +++--- crates/bevy_ecs/src/into_system.rs | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/bevy_ecs/hecs/src/archetype.rs b/crates/bevy_ecs/hecs/src/archetype.rs index f8af785dc9..d8fa99e789 100644 --- a/crates/bevy_ecs/hecs/src/archetype.rs +++ b/crates/bevy_ecs/hecs/src/archetype.rs @@ -106,6 +106,7 @@ impl Archetype { } #[allow(missing_docs)] + #[inline] pub fn get(&self) -> Option> { let state = self.state.get(&TypeId::of::())?; Some(unsafe { diff --git a/crates/bevy_ecs/hecs/src/query.rs b/crates/bevy_ecs/hecs/src/query.rs index 5e66b127e8..0c1846fc27 100644 --- a/crates/bevy_ecs/hecs/src/query.rs +++ b/crates/bevy_ecs/hecs/src/query.rs @@ -72,9 +72,11 @@ impl Query for Entity { impl<'a> Fetch<'a> for EntityFetch { type Item = Entity; + #[inline] fn access(_archetype: &Archetype) -> Option { Some(Access::Iterate) } + #[inline] fn borrow(_archetype: &Archetype) {} #[inline] unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option { @@ -82,6 +84,7 @@ impl<'a> Fetch<'a> for EntityFetch { archetype.entities().as_ptr().add(offset), ))) } + #[inline] fn release(_archetype: &Archetype) {} #[inline] @@ -152,7 +155,6 @@ impl<'a, T: Component> Fetch<'a> for FetchWrite { fn borrow(archetype: &Archetype) { archetype.borrow_mut::(); } - #[inline] unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option { archetype .get::() @@ -162,7 +164,6 @@ impl<'a, T: Component> Fetch<'a> for FetchWrite { archetype.release_mut::(); } - #[inline] unsafe fn next(&mut self) -> &'a mut T { let x = self.0.as_ptr(); self.0 = NonNull::new_unchecked(x.add(1)); @@ -517,7 +518,6 @@ struct ChunkIter { } impl ChunkIter { - #[inline] unsafe fn next<'a, 'w>(&mut self) -> Option<>::Item> { if self.len == 0 { return None; diff --git a/crates/bevy_ecs/src/into_system.rs b/crates/bevy_ecs/src/into_system.rs index dea494bf10..8004640176 100644 --- a/crates/bevy_ecs/src/into_system.rs +++ b/crates/bevy_ecs/src/into_system.rs @@ -53,6 +53,7 @@ where self.thread_local_execution } + #[inline] fn run(&mut self, world: &World, resources: &Resources) { (self.func)(world, resources, &self.archetype_access, &mut self.state); } @@ -102,9 +103,8 @@ macro_rules! impl_into_foreach_system { <<($($resource,)*) as ResourceQuery>::Fetch as FetchResource>::borrow(&resources.resource_archetypes); { let ($($resource,)*) = resources.query_system::<($($resource,)*)>(id); - let commands = state.clone(); for ($($component,)*) in world.query::<($($component,)*)>().iter() { - fn_call!(self, ($($commands, commands)*), ($($resource),*), ($($component),*)) + fn_call!(self, ($($commands, state)*), ($($resource),*), ($($component),*)) } } <<($($resource,)*) as ResourceQuery>::Fetch as FetchResource>::release(&resources.resource_archetypes); @@ -242,7 +242,7 @@ macro_rules! impl_into_query_system { i += 1; )* - let commands = state.commands.clone(); + let commands = &state.commands; fn_call!(self, ($($commands, commands)*), ($($resource),*), ($($query),*)) } <<($($resource,)*) as ResourceQuery>::Fetch as FetchResource>::release(&resources.resource_archetypes);