Skip to content

Don't create errors for ignored failed commands #19718

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

brianreavis
Copy link
Contributor

@brianreavis brianreavis commented Jun 18, 2025

Objective

  1. Reduce overhead from error handling for ECS commands that intentionally ignore errors, such as try_despawn. These commands currently allocate error objects and pass them to a no-op handler (ignore), which can impact performance when many operations fail.

  2. Fix a hang when removing ChildOf components during entity despawning. Excessive logging of these failures can cause significant hangs (I'm noticing around 100ms).

image

Solution

  • Added a ignore_error method to the HandleError trait to use instead of handle_error_with(ignore). It swallows errors and does not create error objects.
  • Replaced remove::<ChildOf> with try_remove::<ChildOf> to suppress expected (?) errors and reduce log noise.

Testing

  • I ran these changes on a local project.

@brianreavis brianreavis changed the title Don't create errors for ignored failed commands Don't create errors for ignored failed commands + Jun 18, 2025
@brianreavis brianreavis changed the title Don't create errors for ignored failed commands + Don't create errors for ignored failed commands Jun 18, 2025
@brianreavis brianreavis marked this pull request as draft June 18, 2025 15:43
@brianreavis brianreavis added A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 18, 2025
@brianreavis brianreavis marked this pull request as ready for review June 18, 2025 16:28
fn handle_error_with(self, error_handler: ErrorHandler) -> impl Command;
///
/// If `None` is provided, the error will be completely ignored.
fn handle_error_with(self, error_handler: Option<ErrorHandler>) -> impl Command;
Copy link
Contributor

Choose a reason for hiding this comment

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

As someone who often fails to read documentation, I would probably have expected .handle_error_with(None) to be the same as .handle_error(), but one does "ignore" and the other does "default".

It looks like we always know at compile time whether we want Some or None here. Would it work to make a separate method like fn ignore_error(self) -> impl Command? That might even remove a runtime branch.

(If we do want a runtime switch between the behaviors, then maybe it could be something like enum ErrorHandler { Default, Ignore, Custom(fn(BevyError, ErrorContext)) } so that it can cover handle_error, as well.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! Implemented the former.

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-Performance A change motivated by improving speed, memory usage or compile times D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Entity does not exist" warning triggered by DespawnOnExitState for all child components Warning: missing IDs in observer_propagation
2 participants