bevy/crates/bevy_ui/src
Patrick Walton 5caf085dac
Divide the single VisibleEntities list into separate lists for 2D meshes, 3D meshes, lights, and UI elements, for performance. (#12582)
This commit splits `VisibleEntities::entities` into four separate lists:
one for lights, one for 2D meshes, one for 3D meshes, and one for UI
elements. This allows `queue_material_meshes` and similar methods to
avoid examining entities that are obviously irrelevant. In particular,
this separation helps scenes with many skinned meshes, as the individual
bones are considered visible entities but have no rendered appearance.

Internally, `VisibleEntities::entities` is a `HashMap` from the `TypeId`
representing a `QueryFilter` to the appropriate `Entity` list. I had to
do this because `VisibleEntities` is located within an upstream crate
from the crates that provide lights (`bevy_pbr`) and 2D meshes
(`bevy_sprite`). As an added benefit, this setup allows apps to provide
their own types of renderable components, by simply adding a specialized
`check_visibility` to the schedule.

This provides a 16.23% end-to-end speedup on `many_foxes` with 10,000
foxes (24.06 ms/frame to 20.70 ms/frame).

## Migration guide

* `check_visibility` and `VisibleEntities` now store the four types of
renderable entities--2D meshes, 3D meshes, lights, and UI
elements--separately. If your custom rendering code examines
`VisibleEntities`, it will now need to specify which type of entity it's
interested in using the `WithMesh2d`, `WithMesh`, `WithLight`, and
`WithNode` types respectively. If your app introduces a new type of
renderable entity, you'll need to add an explicit call to
`check_visibility` to the schedule to accommodate your new component or
components.

## Analysis

`many_foxes`, 10,000 foxes: `main`:
![Screenshot 2024-03-31
114444](https://github.com/bevyengine/bevy/assets/157897/16ecb2ff-6e04-46c0-a4b0-b2fde2084bad)

`many_foxes`, 10,000 foxes, this branch:
![Screenshot 2024-03-31
114256](https://github.com/bevyengine/bevy/assets/157897/94dedae4-bd00-45b2-9aaf-dfc237004ddb)

`queue_material_meshes` (yellow = this branch, red = `main`):
![Screenshot 2024-03-31
114637](https://github.com/bevyengine/bevy/assets/157897/f90912bd-45bd-42c4-bd74-57d98a0f036e)

`queue_shadows` (yellow = this branch, red = `main`):
![Screenshot 2024-03-31
114607](https://github.com/bevyengine/bevy/assets/157897/6ce693e3-20c0-4234-8ec9-a6f191299e2d)
2024-04-11 20:33:20 +00:00
..
layout [bevy_ui/layout] Update tests to get GlobalTransform properly (#12802) 2024-04-03 02:48:06 +00:00
render Consolidate Render(Ui)Materials(2d) into RenderAssets (#12827) 2024-04-09 13:26:34 +00:00
widget feat: derive some common traits on some UI types (#12532) 2024-03-18 03:41:50 +00:00
accessibility.rs resolve all internal ambiguities (#10411) 2024-01-09 19:08:15 +00:00
focus.rs don't attempt to set cursor relative position for zero sized nodes (#12395) 2024-03-10 02:18:40 +00:00
geometry.rs Add with_left, with_right, with_top, with_bottom to UiRect (#12487) 2024-03-15 17:43:39 +00:00
lib.rs Divide the single VisibleEntities list into separate lists for 2D meshes, 3D meshes, lights, and UI elements, for performance. (#12582) 2024-04-11 20:33:20 +00:00
measurement.rs Change the default for the measure_func field of ContentSize to None. (#9346) 2023-08-07 23:06:40 +00:00
node_bundles.rs Add border radius to UI nodes (adopted) (#12500) 2024-03-19 22:44:00 +00:00
stack.rs Reduce steady-state allocations in ui_stack_system (#12413) 2024-03-12 13:57:57 +00:00
texture_slice.rs Add border radius to UI nodes (adopted) (#12500) 2024-03-19 22:44:00 +00:00
ui_material.rs Fix incorrect link in UiMaterial documentation (#12361) 2024-03-07 22:09:57 +00:00
ui_node.rs Forbid unsafe in most crates in the engine (#12684) 2024-03-27 03:30:08 +00:00
update.rs Avoid panicking with non-UI nodes (#12213) 2024-02-29 21:36:45 +00:00