bevy/crates/bevy_ecs/src/storage
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
..
table Nonmax all rows (#19132) 2025-05-26 17:39:55 +00:00
blob_array.rs Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
blob_vec.rs Fix sparse set components ignoring insert_if_new/InsertMode (#19059) 2025-05-05 17:42:36 +00:00
mod.rs Isolate component registration (#17671) 2025-02-05 19:59:30 +00:00
resource.rs Fix lint errors on bevy_ecs with disabled features (#18488) 2025-03-22 16:36:56 +00:00
sparse_set.rs Nonmax all rows (#19132) 2025-05-26 17:39:55 +00:00
thin_array_ptr.rs Use fully qualified syntax in assertions. (#17936) 2025-02-22 01:58:54 +00:00