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

Print a warning for un-applied commands being dropped from a CommandQueue #11146

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Changes from all commits
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
4 changes: 4 additions & 0 deletions crates/bevy_ecs/src/system/commands/command_queue.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::mem::MaybeUninit;

use bevy_ptr::{OwningPtr, Unaligned};
use bevy_utils::tracing::warn;

use super::Command;
use crate::world::World;
Expand Down Expand Up @@ -161,6 +162,9 @@ impl CommandQueue {

impl Drop for CommandQueue {
fn drop(&mut self) {
if !self.bytes.is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should only warn in debug mode and save an additional check here

Copy link
Contributor

Choose a reason for hiding this comment

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

The bevy book recommends compiling bevy with opt-level=3. Disabling in debug mode means people who follow those instructions won't see the warning, making it pretty useless.

I do agree however that we could avoid checks, and additional binary bloat (log statements add a fairly large number of instructions, without counting the log message) But not sure how. I see some alternatives:

  • Use info!, so that the log can be disabled at compile-time using the log/max_level_warn feature
  • (controversial I think) use the detailed_trace feature
  • Add a new feature, enabled by default, something like costly_runtime_checks and use it as a feature gate for the check.

Honestly, I don't prefer any in particular, all have their appeal and tradeoffs, and I don't think it's very important to avoid the check/log here.

Copy link
Member

Choose a reason for hiding this comment

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

The bevy book recommends compiling bevy with opt-level=3. Disabling in debug mode means people who follow those instructions won't see the warning, making it pretty useless.

Debug checks are still included when compiling with optimizations, as long as you don't switch to release mode.

That said, I don't think it's worth spending too much thought on this check. For regular systems, or exclusive systems that properly reuse their SystemState, command queues will only get dropped when the app exit. The only time this check will be called unnecessarily is if users create a new SystemState every time the system runs, which is a performance pitfall of its own that's going to matter a lot more than this check.

warn!("CommandQueue has un-applied commands being dropped.");
}
self.apply_or_drop_queued(None);
}
}
Expand Down