-
-
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
Reduce memory usage in component fetches and change detection filters #15283
Conversation
Co-authored-by: james7132 <[email protected]>
Full ECS benchmark suite results (this PR on left)
|
Code changes seem reasonable, but those benchmark results are super weird. Why would only some of the busy_systems benchmarks have a 40%+ slowdown? Can you rerun them and post the results? |
@alice-i-cecile Reran on a different machine: Full ECS suite benchmarks (this PR on left)
|
Okay, thanks :) I'm happy to call the benchmarks largely noise. Reducing memory usage has its own value though, so I'm in favor. |
It might be nice to add some convenience methods to pub fn new(table: impl FnOnce() -> T, sparse_set: impl FnOnce() -> S) -> Self {
match C::STORAGE_TYPE {
StorageType::Table => Self {
table: ManuallyDrop::new(table()),
},
StorageType::SparseSet => Self {
sparse_set: ManuallyDrop::new(sparse_set()),
},
}
}
pub fn extract<R>(&self, table: impl FnOnce(T) -> R, sparse_set: impl FnOnce(S) -> R) -> R {
match C::STORAGE_TYPE {
StorageType::Table => table(unsafe { *self.table }),
StorageType::SparseSet => sparse_set(unsafe { *self.sparse_set }),
}
} |
Co-authored-by: Chris Russell <[email protected]>
💯 Very good idea, that works out much better. |
…bevyengine#15283) ## Objective - Adopted bevyengine#6396 ## Solution Same as bevyengine#6396, we use a compile-time checked `StorageSwitch` union type to select the fetch data based on the component's storage type, saving >= 8 bytes per component fetch in a given query. Note: We forego the Query iteration change as it exists in a slightly different form now on main. ## Testing - All current tests pass locally. --------- Co-authored-by: james7132 <[email protected]> Co-authored-by: Chris Russell <[email protected]>
Objective
Solution
Same as #6396, we use a compile-time checked
StorageSwitch
union type to select the fetch data based on the component's storage type, saving >= 8 bytes per component fetch in a given query.Note: We forego the Query iteration change as it exists in a slightly different form now on main.
Testing