Reduce memory usage in component fetches and change detection filters#15283
Conversation
Co-authored-by: james7132 <contact@jamessliu.com>
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 <8494645+chescock@users.noreply.github.com>
💯 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 <contact@jamessliu.com> Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
Objective
Solution
Same as #6396, we use a compile-time checked
StorageSwitchunion 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