-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 branching when inserting components #8053
Conversation
Definitely seems like there's a significant gain here. Microbenchmark results below:
Separately noticed that there's still a few potential out-of-bounds panics when creating a BundleInserter or BundleSpawner that could be removed as well, but we can wait to do that in a separate PR. |
It's interesting that all of the benchmarks are a bit faster, except for the spawn_world ones which are all consistently a bit slower. |
I'm not sure where this is coming from. The only change that might affect it in this PR is the changes to |
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.
Thank you for fixing the invariant. I think this PR is in a good state now, got a couple more suggestions though.
Co-authored-by: JoJoJet <21144246+JoJoJet@users.noreply.github.com>
Objective
We're currently using an unconditional
unwrap
in multiple locations when inserting bundles into an entity when we know it will never fail. This adds a large amount of extra branching that could be avoided on in release builds.Solution
Use
DebugCheckedUnwrap
in bundle insertion code where relevant. Add and update the safety comments to match.This should remove the panicking branches from release builds, which has a significant impact on the generated code: https://github.com/james7132/bevy_asm_tests/compare/less-panicking-bundles#diff-e55a27cfb1615846ed3b6472f15a1aed66ed394d3d0739b3117f95cf90f46951R2086 shows about a 10% reduction in the number of generated instructions for
EntityMut::insert
,EntityMut::remove
,EntityMut::take
, and related functions.