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

Conversation

garychia
Copy link
Contributor

Objective

Solution

Add a warning for un-applied commands to the drop function.

@nicopap nicopap added the A-ECS Entities, components, systems, and events label Dec 30, 2023
@@ -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.

@nicopap
Copy link
Contributor

nicopap commented Dec 30, 2023

Here is a gist with code to test the feature:

https://gist.github.com/nicopap/cbff7a6dd36df728dd73ec40914bf931

It should show the warn, and when line 38 is uncommented, it shouldn't.

@alice-i-cecile alice-i-cecile added the C-Usability A targeted quality-of-life change that makes Bevy easier to use label Jan 3, 2024
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jan 3, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 3, 2024
Merged via the queue into bevyengine:main with commit b6da40c Jan 3, 2024
26 checks passed
@garychia garychia deleted the command_drop_warning branch January 4, 2024 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Print a warning if a CommandQueue gets dropped with un-applied commands
5 participants