bevy/crates
JaySpruce 4fde223831
Optimize Entities::entity_does_not_exist_error_details_message, remove UnsafeWorldCell from error (#17115)
## Objective

The error `EntityFetchError::NoSuchEntity` has an `UnsafeWorldCell`
inside it, which it uses to call
`Entities::entity_does_not_exist_error_details_message` when being
printed. That method returns a `String` that, if the `track_location`
feature is enabled, contains the location of whoever despawned the
relevant entity.

I initially had to modify this error while working on #17043. The
`UnsafeWorldCell` was causing borrow problems when being returned from a
command, so I tried replacing it with the `String` that the method
returns, since that was the world cell's only purpose.

Unfortunately, `String`s are slow, and it significantly impacted
performance (on top of that PR's performance hit):
<details>
<summary>17043 benchmarks</summary>

### With `String`

![error_handling_insert_slow](https://github.com/user-attachments/assets/5629ba6d-69fc-4c16-84c9-8be7e449232d)

### No `String`

![error_handling_insert_fixed](https://github.com/user-attachments/assets/6393e2d6-e61a-4558-8ff1-471ff8356c1c)

</details>

For that PR, I just removed the error details entirely, but I figured
I'd try to find a way to keep them around.

## Solution

- Replace the `String` with a helper struct that holds the location, and
only turn it into a string when someone actually wants to print it.
- Replace the `UnsafeWorldCell` with the aforementioned struct.
- Do the same for `QueryEntityError::NoSuchEntity`.

## Benchmarking

This had some interesting performance impact:

<details>
<summary>This PR vs main</summary>


![dne_rework_1](https://github.com/user-attachments/assets/05bf91b4-dddc-4d76-b2c4-41c9d25c7a57)

![dne_rework_2](https://github.com/user-attachments/assets/34aa76b2-d8a7-41e0-9670-c213207e457d)

![dne_rework_3](https://github.com/user-attachments/assets/8b9bd4e4-77c8-45a7-b058-dc0dfd3dd323)

</details>

## Other work

`QueryEntityError::QueryDoesNotMatch` also has an `UnsafeWorldCell`
inside it. This one would be more complicated to rework while keeping
the same functionality.

## Migration Guide

The errors `EntityFetchError::NoSuchEntity` and
`QueryEntityError::NoSuchEntity` now contain an
`EntityDoesNotExistDetails` struct instead of an `UnsafeWorldCell`. If
you were just printing these, they should work identically.

---------

Co-authored-by: Benjamin Brienen <benjamin.brienen@outlook.com>
2025-01-05 02:01:01 +00:00
..
bevy_a11y bevy_a11y: Apply #[deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17093) 2025-01-02 18:45:19 +00:00
bevy_animation bevy_animation: Apply #[deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17094) 2025-01-02 18:45:05 +00:00
bevy_app Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
bevy_asset Do not lowercase asset file extensions (#17065) 2025-01-01 00:42:56 +00:00
bevy_audio Prefer Display over Debug (#16112) 2024-12-27 00:40:06 +00:00
bevy_color Truncate the floats in bevy_color::oklaba (#17109) 2025-01-03 22:20:51 +00:00
bevy_core_pipeline Update typos (#17126) 2025-01-03 17:44:26 +00:00
bevy_derive Add benchmarks and compile_fail tests back to workspace (#16858) 2024-12-21 22:30:29 +00:00
bevy_dev_tools Draw the UI debug overlay using the UI renderer (#16693) 2024-12-11 00:49:47 +00:00
bevy_diagnostic Remove bevy_core (#16897) 2024-12-19 18:36:51 +00:00
bevy_dylib Generate links to definition in source code pages on docs.rs and dev-docs.bevyengine.org (#12965) 2024-07-29 23:10:16 +00:00
bevy_ecs Optimize Entities::entity_does_not_exist_error_details_message, remove UnsafeWorldCell from error (#17115) 2025-01-05 02:01:01 +00:00
bevy_encase_derive Rust 1.83, allow -> expect (missing_docs) (#16561) 2024-12-16 23:27:57 +00:00
bevy_gilrs Deny derive_more error feature and replace it with thiserror (#16684) 2024-12-06 17:03:55 +00:00
bevy_gizmos Refactor non-core Curve methods into extension traits (#16930) 2024-12-29 19:26:49 +00:00
bevy_gltf Prefer Display over Debug (#16112) 2024-12-27 00:40:06 +00:00
bevy_hierarchy Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
bevy_image Rust 1.83, allow -> expect (missing_docs) (#16561) 2024-12-16 23:27:57 +00:00
bevy_input Scale input to account for deadzones (#17015) 2025-01-03 22:27:59 +00:00
bevy_input_focus Return Result from tab navigation API (#17071) 2025-01-01 04:05:48 +00:00
bevy_internal Rename track_change_detection flag to track_location (#17075) 2025-01-01 18:43:47 +00:00
bevy_log Basic filtering examples for users of the bevy_log. (#16455) 2024-12-29 22:56:40 +00:00
bevy_macro_utils Use one BevyManifest instance in proc macros (#16766) 2024-12-15 15:00:05 +00:00
bevy_math Update typos (#17126) 2025-01-03 17:44:26 +00:00
bevy_mesh Rust 1.83, allow -> expect (missing_docs) (#16561) 2024-12-16 23:27:57 +00:00
bevy_mikktspace Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
bevy_pbr Update typos (#17126) 2025-01-03 17:44:26 +00:00
bevy_picking Update typos (#17126) 2025-01-03 17:44:26 +00:00
bevy_ptr Fix MSRVs for standalone crates (#16333) 2024-11-17 09:38:13 +00:00
bevy_reflect bevy_reflect: Apply #[deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17092) 2025-01-03 22:22:34 +00:00
bevy_remote show these 'fully qualified paths' for bevy_remote's rpc (#16944) 2024-12-31 00:29:27 +00:00
bevy_render Refactor and simplify custom projections (#17063) 2025-01-01 20:44:24 +00:00
bevy_scene Replace map + unwrap_or(true) with is_none_or (#17070) 2024-12-31 20:17:03 +00:00
bevy_sprite Revert "Fix sprite performance regression since retained render world (#17078)" (#17123) 2025-01-04 00:22:18 +00:00
bevy_state Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
bevy_tasks Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
bevy_text Revert "Fix sprite performance regression since retained render world (#17078)" (#17123) 2025-01-04 00:22:18 +00:00
bevy_time Use en-us locale for typos (#16037) 2024-10-20 18:55:17 +00:00
bevy_transform Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
bevy_ui UI Debug Overlay show_hidden and show_clipped options (#17097) 2025-01-02 18:43:14 +00:00
bevy_utils Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
bevy_window Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
bevy_winit Simplify sort/max_by calls (#17048) 2024-12-30 22:59:36 +00:00