Skip to content
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

Closed

Conversation

TheRawMeatball
Copy link
Member

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.

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Oct 14, 2021
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times S-Needs-Review and removed S-Needs-Triage This issue needs to be labelled labels Oct 14, 2021
@alice-i-cecile
Copy link
Member

Do we have any existing benchmarks that would be appropriate for this?

Copy link
Member

@BoxyUwU BoxyUwU left a 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

crates/bevy_ecs/src/system/query.rs Outdated Show resolved Hide resolved
@@ -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)> {
Copy link
Member

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?

@alice-i-cecile
Copy link
Member

looks good other than this

I'm counting this as an approval.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Feb 4, 2022
@cart
Copy link
Member

cart commented Feb 8, 2022

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.

@alice-i-cecile
Copy link
Member

@TheRawMeatball, when you get a chance can you rebase this? We have ECS benchmarks now; I can give running the comparison a shot.

@TheRawMeatball
Copy link
Member Author

TheRawMeatball commented Apr 26, 2022

I'll rebase this and run benches later today, though I don't think we have any benchmarks for this function.

@alice-i-cecile
Copy link
Member

Fair enough. I'll see about adding some in a separate PR.

bors bot pushed a commit that referenced this pull request Apr 26, 2022
# Objective

Add a benchmark to measure the performance of get_component, particularly for cases involving random access.

Enables #2965
bors bot pushed a commit that referenced this pull request Apr 26, 2022
# Objective

Add a benchmark to measure the performance of get_component, particularly for cases involving random access.

Enables #2965
@alice-i-cecile
Copy link
Member

@TheRawMeatball merge conflicts and failing CI for you <3 We should also double-check those benchmarks, if only for the release notes hype.

@alice-i-cecile alice-i-cecile added S-Needs-Benchmarking This set of changes needs performance benchmarking to double-check that they help and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels May 16, 2022
exjam pushed a commit to exjam/bevy that referenced this pull request May 22, 2022
# Objective

Add a benchmark to measure the performance of get_component, particularly for cases involving random access.

Enables bevyengine#2965
@alice-i-cecile alice-i-cecile added the S-Adopt-Me The original PR author has no intent to complete this work. Pick me up! label Jan 16, 2023
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

Add a benchmark to measure the performance of get_component, particularly for cases involving random access.

Enables bevyengine#2965
@tygyh
Copy link
Contributor

tygyh commented Jan 28, 2024

Since get_component has changed a lot since this PR was opened, is there a reason to keep it open?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times S-Adopt-Me The original PR author has no intent to complete this work. Pick me up! S-Needs-Benchmarking This set of changes needs performance benchmarking to double-check that they help
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants