Move system_commands spans into apply_buffers (#6900)
# Objective A separate `tracing` span for running a system's commands is created, even if the system doesn't have commands. This is adding extra measuring overhead (see #4892) where it's not needed. ## Solution Move the span into `ParallelCommandState` and `CommandQueue`'s `SystemParamState::apply`. To get the right metadata for the span, a additional `&SystemMeta` parameter was added to `SystemParamState::apply`. --- ## Changelog Added: `SystemMeta::name` Changed: Systems without `Commands` and `ParallelCommands` will no longer show a "system_commands" span when profiling. Changed: `SystemParamState::apply` now takes a `&SystemMeta` parameter in addition to the provided `&mut World`.
This commit is contained in:
parent
4820917af6
commit
79b9231b74
@ -285,8 +285,8 @@ pub fn impl_param_set(_input: TokenStream) -> TokenStream {
|
|||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply(&mut self, world: &mut World) {
|
fn apply(&mut self, system_meta: &SystemMeta, world: &mut World) {
|
||||||
self.0.apply(world)
|
self.0.apply(system_meta, world)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -466,8 +466,8 @@ pub fn derive_system_param(input: TokenStream) -> TokenStream {
|
|||||||
self.state.new_archetype(archetype, system_meta)
|
self.state.new_archetype(archetype, system_meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply(&mut self, world: &mut #path::world::World) {
|
fn apply(&mut self, system_meta: &#path::system::SystemMeta, world: &mut #path::world::World) {
|
||||||
self.state.apply(world)
|
self.state.apply(system_meta, world)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn get_param<'w, 's>(
|
unsafe fn get_param<'w, 's>(
|
||||||
|
|||||||
@ -229,12 +229,10 @@ impl SystemStage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_buffers(&mut self, world: &mut World) {
|
pub fn apply_buffers(&mut self, world: &mut World) {
|
||||||
for container in &mut self.parallel {
|
|
||||||
let system = container.system_mut();
|
|
||||||
#[cfg(feature = "trace")]
|
#[cfg(feature = "trace")]
|
||||||
let _span = bevy_utils::tracing::info_span!("system_commands", name = &*system.name())
|
let _span = bevy_utils::tracing::info_span!("stage::apply_buffers").entered();
|
||||||
.entered();
|
for container in &mut self.parallel {
|
||||||
system.apply_buffers(world);
|
container.system_mut().apply_buffers(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -781,17 +779,9 @@ impl Stage for SystemStage {
|
|||||||
.entered();
|
.entered();
|
||||||
container.system_mut().run((), world);
|
container.system_mut().run((), world);
|
||||||
}
|
}
|
||||||
{
|
|
||||||
#[cfg(feature = "trace")]
|
|
||||||
let _system_span = bevy_utils::tracing::info_span!(
|
|
||||||
"system_commands",
|
|
||||||
name = &*container.name()
|
|
||||||
)
|
|
||||||
.entered();
|
|
||||||
container.system_mut().apply_buffers(world);
|
container.system_mut().apply_buffers(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Run parallel systems using the executor.
|
// Run parallel systems using the executor.
|
||||||
// TODO: hard dependencies, nested sets, whatever... should be evaluated here.
|
// TODO: hard dependencies, nested sets, whatever... should be evaluated here.
|
||||||
@ -813,28 +803,14 @@ impl Stage for SystemStage {
|
|||||||
.entered();
|
.entered();
|
||||||
container.system_mut().run((), world);
|
container.system_mut().run((), world);
|
||||||
}
|
}
|
||||||
{
|
|
||||||
#[cfg(feature = "trace")]
|
|
||||||
let _system_span = bevy_utils::tracing::info_span!(
|
|
||||||
"system_commands",
|
|
||||||
name = &*container.name()
|
|
||||||
)
|
|
||||||
.entered();
|
|
||||||
container.system_mut().apply_buffers(world);
|
container.system_mut().apply_buffers(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Apply parallel systems' buffers.
|
// Apply parallel systems' buffers.
|
||||||
if self.apply_buffers {
|
if self.apply_buffers {
|
||||||
for container in &mut self.parallel {
|
for container in &mut self.parallel {
|
||||||
if container.should_run {
|
if container.should_run {
|
||||||
#[cfg(feature = "trace")]
|
|
||||||
let _span = bevy_utils::tracing::info_span!(
|
|
||||||
"system_commands",
|
|
||||||
name = &*container.name()
|
|
||||||
)
|
|
||||||
.entered();
|
|
||||||
container.system_mut().apply_buffers(world);
|
container.system_mut().apply_buffers(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -852,17 +828,9 @@ impl Stage for SystemStage {
|
|||||||
.entered();
|
.entered();
|
||||||
container.system_mut().run((), world);
|
container.system_mut().run((), world);
|
||||||
}
|
}
|
||||||
{
|
|
||||||
#[cfg(feature = "trace")]
|
|
||||||
let _system_span = bevy_utils::tracing::info_span!(
|
|
||||||
"system_commands",
|
|
||||||
name = &*container.name()
|
|
||||||
)
|
|
||||||
.entered();
|
|
||||||
container.system_mut().apply_buffers(world);
|
container.system_mut().apply_buffers(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Check for old component and system change ticks
|
// Check for old component and system change ticks
|
||||||
self.check_change_ticks(world);
|
self.check_change_ticks(world);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use thread_local::ThreadLocal;
|
|||||||
use crate::{
|
use crate::{
|
||||||
entity::Entities,
|
entity::Entities,
|
||||||
prelude::World,
|
prelude::World,
|
||||||
system::{SystemParam, SystemParamState},
|
system::{SystemMeta, SystemParam, SystemParamState},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{CommandQueue, Commands};
|
use super::{CommandQueue, Commands};
|
||||||
@ -60,7 +60,11 @@ unsafe impl SystemParamState for ParallelCommandsState {
|
|||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply(&mut self, world: &mut World) {
|
fn apply(&mut self, _system_meta: &SystemMeta, world: &mut World) {
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let _system_span =
|
||||||
|
bevy_utils::tracing::info_span!("system_commands", name = _system_meta.name())
|
||||||
|
.entered();
|
||||||
for cq in &mut self.thread_local_storage {
|
for cq in &mut self.thread_local_storage {
|
||||||
cq.get_mut().apply(world);
|
cq.get_mut().apply(world);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,6 +37,12 @@ impl SystemMeta {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the system's name
|
||||||
|
#[inline]
|
||||||
|
pub fn name(&self) -> &str {
|
||||||
|
&self.name
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if the system is [`Send`].
|
/// Returns true if the system is [`Send`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_send(&self) -> bool {
|
pub fn is_send(&self) -> bool {
|
||||||
@ -182,7 +188,7 @@ impl<Param: SystemParam> SystemState<Param> {
|
|||||||
/// This function should be called manually after the values returned by [`SystemState::get`] and [`SystemState::get_mut`]
|
/// This function should be called manually after the values returned by [`SystemState::get`] and [`SystemState::get_mut`]
|
||||||
/// are finished being used.
|
/// are finished being used.
|
||||||
pub fn apply(&mut self, world: &mut World) {
|
pub fn apply(&mut self, world: &mut World) {
|
||||||
self.param_state.apply(world);
|
self.param_state.apply(&self.meta, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -416,7 +422,7 @@ where
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn apply_buffers(&mut self, world: &mut World) {
|
fn apply_buffers(&mut self, world: &mut World) {
|
||||||
let param_state = self.param_state.as_mut().expect(Self::PARAM_MESSAGE);
|
let param_state = self.param_state.as_mut().expect(Self::PARAM_MESSAGE);
|
||||||
param_state.apply(world);
|
param_state.apply(&self.system_meta, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@ -140,7 +140,8 @@ pub unsafe trait SystemParamState: Send + Sync + 'static {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn new_archetype(&mut self, _archetype: &Archetype, _system_meta: &mut SystemMeta) {}
|
fn new_archetype(&mut self, _archetype: &Archetype, _system_meta: &mut SystemMeta) {}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn apply(&mut self, _world: &mut World) {}
|
#[allow(unused_variables)]
|
||||||
|
fn apply(&mut self, system_meta: &SystemMeta, _world: &mut World) {}
|
||||||
|
|
||||||
type Item<'world, 'state>: SystemParam<State = Self>;
|
type Item<'world, 'state>: SystemParam<State = Self>;
|
||||||
/// # Safety
|
/// # Safety
|
||||||
@ -615,7 +616,11 @@ unsafe impl SystemParamState for CommandQueue {
|
|||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply(&mut self, world: &mut World) {
|
fn apply(&mut self, _system_meta: &SystemMeta, world: &mut World) {
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let _system_span =
|
||||||
|
bevy_utils::tracing::info_span!("system_commands", name = _system_meta.name())
|
||||||
|
.entered();
|
||||||
self.apply(world);
|
self.apply(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1473,9 +1478,9 @@ macro_rules! impl_system_param_tuple {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn apply(&mut self, _world: &mut World) {
|
fn apply(&mut self, _system_meta: &SystemMeta, _world: &mut World) {
|
||||||
let ($($param,)*) = self;
|
let ($($param,)*) = self;
|
||||||
$($param.apply(_world);)*
|
$($param.apply(_system_meta, _world);)*
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1611,8 +1616,8 @@ unsafe impl<S: SystemParamState, P: SystemParam<State = S> + 'static> SystemPara
|
|||||||
self.0.new_archetype(archetype, system_meta);
|
self.0.new_archetype(archetype, system_meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply(&mut self, world: &mut World) {
|
fn apply(&mut self, system_meta: &SystemMeta, world: &mut World) {
|
||||||
self.0.apply(world);
|
self.0.apply(system_meta, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn get_param<'world, 'state>(
|
unsafe fn get_param<'world, 'state>(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user