-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
base: main
Are you sure you want to change the base?
Conversation
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; |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
Objective
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.Fix a hang when removing
ChildOf
components during entity despawning. Excessive logging of these failures can cause significant hangs (I'm noticing around 100ms).DespawnOnExitState
for all child components #19777observer_propagation
#19753Solution
ignore_error
method to theHandleError
trait to use instead ofhandle_error_with(ignore)
. It swallows errors and does not create error objects.remove::<ChildOf>
withtry_remove::<ChildOf>
to suppress expected (?) errors and reduce log noise.Testing