bevy/crates/bevy_ecs/src/query
Eagster b6b54912fa
Nonmax all rows (#19132)
# Objective

Since #18704 is done, we can track the length of unique entity row
collections with only a `u32` and identify an index within that
collection with only a `NonMaxU32`. This leaves an opportunity for
performance improvements.

## Solution

- Use `EntityRow` in sparse sets.
- Change table, entity, and query lengths to be `u32` instead of
`usize`.
- Keep `batching` module `usize` based since that is reused for events,
which may exceed `u32::MAX`.
- Change according `Range<usize>` to `Range<u32>`. This is more
efficient and helps justify safety.
- Change `ArchetypeRow` and `TableRow` to wrap `NonMaxU32` instead of
`u32`.

Justifying `NonMaxU32::new_unchecked` everywhere is predicated on this
safety comment in `Entities::set`: "`location` must be valid for the
entity at `index` or immediately made valid afterwards before handing
control to unknown code." This ensures no entity is in two table rows
for example. That fact is used to argue uniqueness of the entity rows in
each table, archetype, sparse set, query, etc. So if there's no
duplicates, and a maximum total entities of `u32::MAX` none of the
corresponding row ids / indexes can exceed `NonMaxU32`.

## Testing

CI

---------

Co-authored-by: Christian Hughes <9044780+ItsDoot@users.noreply.github.com>
2025-05-26 17:39:55 +00:00
..
access.rs Let FilteredEntity(Ref|Mut) receive access when nested. (#18236) 2025-05-05 23:23:46 +00:00
builder.rs Let FilteredEntity(Ref|Mut) receive access when nested. (#18236) 2025-05-05 23:23:46 +00:00
error.rs Remove lifetime from QueryEntityError (#18157) 2025-03-09 20:05:22 +00:00
fetch.rs Nonmax all rows (#19132) 2025-05-26 17:39:55 +00:00
filter.rs Nonmax all rows (#19132) 2025-05-26 17:39:55 +00:00
iter.rs Nonmax all rows (#19132) 2025-05-26 17:39:55 +00:00
mod.rs Generic system config (#17962) 2025-03-12 00:12:30 +00:00
par_iter.rs Nonmax all rows (#19132) 2025-05-26 17:39:55 +00:00
state.rs Nonmax all rows (#19132) 2025-05-26 17:39:55 +00:00
world_query.rs Let FilteredEntity(Ref|Mut) receive access when nested. (#18236) 2025-05-05 23:23:46 +00:00