-
-
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
Optimize Query::get_component #2965
Optimize Query::get_component #2965
Conversation
Do we have any existing benchmarks that would be appropriate for this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good other than this
Co-authored-by: Boxy <supbscripter@gmail.com>
crates/bevy_ecs/src/query/filter.rs
Outdated
@@ -503,6 +518,10 @@ macro_rules! impl_tick_filter { | |||
fn matches_table(&self, table: &Table) -> bool { | |||
table.has_column(self.component_id) | |||
} | |||
|
|||
fn get_id<Comp: 'static>(&self) -> Option<(ComponentId, RWAccess)> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make these functions const?
I'm counting this as an approval. |
I'd like to see some benchmark results before merging this, given that performance is the motivator behind the change, this increases code complexity, and bevy_ecs perf is notoriously fickle. |
@TheRawMeatball, when you get a chance can you rebase this? We have ECS benchmarks now; I can give running the comparison a shot. |
I'll rebase this and run benches later today, though I don't think we have any benchmarks for this function. |
Fair enough. I'll see about adding some in a separate PR. |
# Objective Add a benchmark to measure the performance of get_component, particularly for cases involving random access. Enables #2965
# Objective Add a benchmark to measure the performance of get_component, particularly for cases involving random access. Enables #2965
@TheRawMeatball merge conflicts and failing CI for you <3 We should also double-check those benchmarks, if only for the release notes hype. |
# Objective Add a benchmark to measure the performance of get_component, particularly for cases involving random access. Enables bevyengine#2965
# Objective Add a benchmark to measure the performance of get_component, particularly for cases involving random access. Enables bevyengine#2965
Since get_component has changed a lot since this PR was opened, is there a reason to keep it open? |
Right now Query::get_component creates a new EntityRef per get call, and then uses get_unchecked methods to get the data, causing more lookups and branches than necessary. This PR optimizes get_component by taking advantage of data already cached on Query s and taking advantage of derive component to const-ify certain branches.