Skip to content

many_components stress test improvements#16913

Merged
alice-i-cecile merged 16 commits intobevyengine:mainfrom
hymm:fix-many-components
Feb 10, 2025
Merged

many_components stress test improvements#16913
alice-i-cecile merged 16 commits intobevyengine:mainfrom
hymm:fix-many-components

Conversation

@hymm
Copy link
Copy Markdown
Contributor

@hymm hymm commented Dec 20, 2024

Objective

  • I was getting familiar with the many_components example to test some recent pr's for executor changes and saw some things to improve.

Solution

  • Use insert_by_ids instead of insert_by_id. This reduces the number of archetype moves and improves startup times substantially.
  • Add a tracing span to base_system. I'm not sure why, but tracing spans weren't showing for this system. I think it's something to do with how pipe system works, but need to investigate more. The approach in this pr is a little better than the default span too, since it allows adding the number of entities queried to the span which is not possible with the default system span.
  • println the number of archetype component id's that are created. This is useful since part of the purpose of this stress test is to test how well the use of FixedBitSet scales in the executor.

Testing

  • Ran the example with cargo run --example many_components -F trace_tracy 1000000 and connected with tracy
  • Timed the time it took to spawn 1 million entities on main (240 s) vs this pr (15 s)

Showcase

image

Future Work

  • Currently systems are created with a random set of components and entities are created with a random set of components without any correlation between the randomness. This means that some systems won't match any entities and some entities could not match any systems. It might be better to spawn the entities from the pool of components that match the queries that the systems are using.

@hymm hymm added C-Examples An addition or correction to our examples A-ECS Entities, components, systems, and events C-Benchmarks Stress tests and benchmarks used to measure how fast things are D-Straightforward Simple bug fixes and API improvements, docs, test and examples and removed C-Examples An addition or correction to our examples labels Dec 20, 2024
}
}

println!(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be info! so it can be configured with the logging framework?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. I see some examples use info and some use println. This example was using println already, so I just kept it consistent.

@hymm hymm added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Dec 24, 2024
@BenjaminBrienen BenjaminBrienen added the D-Unsafe Touches with unsafe code in some way label Dec 24, 2024
@BenjaminBrienen
Copy link
Copy Markdown
Contributor

Needing unsafe in the benchmarks makes me feel like we could improve the API.

@hymm
Copy link
Copy Markdown
Contributor Author

hymm commented Dec 24, 2024

Needing unsafe in the benchmarks makes me feel like we could improve the API.

it's because we're spawning things dynamically, for which I don't think we can avoid unsafe.

@BenjaminBrienen BenjaminBrienen added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 22, 2025
@hymm hymm force-pushed the fix-many-components branch from d95764b to f6b5150 Compare January 31, 2025 19:41
@hymm
Copy link
Copy Markdown
Contributor Author

hymm commented Feb 7, 2025

I added a optional dependency on the tracing lib to the base Cargo.toml which is enabled with the trace feature. This shouldn't be a major change as tracing should already be in the dependency tree when that feature is enabled.

@hymm hymm added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Feb 7, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 10, 2025
Merged via the queue into bevyengine:main with commit 8e84b46 Feb 10, 2025
@hymm hymm deleted the fix-many-components branch January 22, 2026 23:55
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-Benchmarks Stress tests and benchmarks used to measure how fast things are D-Straightforward Simple bug fixes and API improvements, docs, test and examples D-Unsafe Touches with unsafe code in some way S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants