-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Merged by Bors] - Use u32 over usize for ComponentSparseSet indicies #4723
Conversation
As @TheRawMeatball stated, the cast is likely inconsequential. Here are the relevant benchmark results, most of these are within a reasonable margin of error, but there are notable speedups in sparse set iteration with the indexes being smaller, and thus a bit more cache friendly.
|
@bevyengine/ecs-team more performance optimizations that are ready to review. |
To add to this, a lot of the stored usizes we have could also be u32s. Most notably Archetype::entity_table_rows, which could speed up archetype based iteration in general. I'll leave this for a separate PR so we can benchmark each part in isolation. |
bors r+ |
# Objective Use less memory to store SparseSet components. ## Solution Change `ComponentSparseSet` to only use `Entity::id` in it's key internally, and change the usize value in it's SparseArray to use u32 instead, as it cannot have more than u32::MAX live entities stored at once. This should reduce the overhead of storing components in sparse set storage by 50%.
This appears to have caused a failure on release builds. EDIT: @james7132 said they'll tackle this, the problem is with the debug asserts getting compiled in release mode, where the types differ.
|
# Objective Use less memory to store SparseSet components. ## Solution Change `ComponentSparseSet` to only use `Entity::id` in it's key internally, and change the usize value in it's SparseArray to use u32 instead, as it cannot have more than u32::MAX live entities stored at once. This should reduce the overhead of storing components in sparse set storage by 50%.
# Objective Use less memory to store SparseSet components. ## Solution Change `ComponentSparseSet` to only use `Entity::id` in it's key internally, and change the usize value in it's SparseArray to use u32 instead, as it cannot have more than u32::MAX live entities stored at once. This should reduce the overhead of storing components in sparse set storage by 50%.
Objective
Use less memory to store SparseSet components.
Solution
Change
ComponentSparseSet
to only useEntity::id
in it's key internally, and change the usize value in it's SparseArray to use u32 instead, as it cannot have more than u32::MAX live entities stored at once.This should reduce the overhead of storing components in sparse set storage by 50%.