Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache System Tracing Spans #9390

Merged
merged 7 commits into from
Sep 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move spans to task meta data struct
  • Loading branch information
hymm committed Aug 15, 2023
commit cabaece383b18dd3a5ed5f10fdee62d609c4f2ee
41 changes: 18 additions & 23 deletions crates/bevy_ecs/src/schedule/executor/multi_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ struct SystemTaskMetadata {
is_send: bool,
/// Is `true` if the system is exclusive.
is_exclusive: bool,
/// Cached tracing span for system task
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Cached tracing span for system task
/// Tracing span for system task, cached for performance.

#[cfg(feature = "trace")]
system_task_span: Span,
/// Cached tracing span for system
#[cfg(feature = "trace")]
system_span: Span,
}

/// The result of running a system that is sent across a channel.
Expand Down Expand Up @@ -112,12 +118,6 @@ pub struct MultiThreadedExecutor {
panic_payload: Arc<Mutex<Option<Box<dyn Any + Send>>>>,
/// When set, stops the executor from running any more systems.
stop_spawning: bool,
/// Cached tracing spans for system tasks
#[cfg(feature = "trace")]
system_task_spans: Vec<Span>,
/// Cached tracing spans for systems
#[cfg(feature = "trace")]
system_spans: Vec<Span>,
}

impl Default for MultiThreadedExecutor {
Expand Down Expand Up @@ -153,24 +153,23 @@ impl SystemExecutor for MultiThreadedExecutor {
self.unapplied_systems = FixedBitSet::with_capacity(sys_count);

self.system_task_metadata = Vec::with_capacity(sys_count);
#[cfg(feature = "trace")]
{
self.system_task_spans = Vec::with_capacity(sys_count);
self.system_spans = Vec::with_capacity(sys_count);
}
for index in 0..sys_count {
self.system_task_metadata.push(SystemTaskMetadata {
archetype_component_access: default(),
dependents: schedule.system_dependents[index].clone(),
is_send: schedule.systems[index].is_send(),
is_exclusive: schedule.systems[index].is_exclusive(),
#[cfg(feature = "trace")]
system_task_span: info_span!(
"system_task",
name = &*schedule.systems[index].name()
),
#[cfg(feature = "trace")]
system_span: info_span!(
"system",
name = &*schedule.systems[index].name()
),
});

#[cfg(feature = "trace")]
{
self.system_task_spans.push(info_span!("system_task", name = &*schedule.systems[index].name()));
self.system_spans.push(info_span!("system", name = &*schedule.systems[index].name()));
}
}

self.num_dependencies_remaining = Vec::with_capacity(sys_count);
Expand Down Expand Up @@ -299,10 +298,6 @@ impl MultiThreadedExecutor {
apply_final_deferred: true,
panic_payload: Arc::new(Mutex::new(None)),
stop_spawning: false,
#[cfg(feature = "trace")]
system_task_spans: Vec::new(),
#[cfg(feature = "trace")]
system_spans: Vec::new(),
}
}

Expand Down Expand Up @@ -509,7 +504,7 @@ impl MultiThreadedExecutor {
let system = unsafe { &mut *systems[system_index].get() };

#[cfg(feature = "trace")]
let system_span = self.system_spans[system_index].clone();
let system_span = self.system_task_metadata[system_index].system_span.clone();

let sender = self.sender.clone();
let panic_payload = self.panic_payload.clone();
Expand Down Expand Up @@ -543,7 +538,7 @@ impl MultiThreadedExecutor {
};

#[cfg(feature = "trace")]
let task = task.instrument(self.system_task_spans[system_index].clone());
let task = task.instrument(self.system_task_metadata[system_index].system_task_span.clone());

let system_meta = &self.system_task_metadata[system_index];
self.active_access
Expand Down