-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Bundle refactor - Option
bundles and Box<dyn Bundle>
#19491
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
base: main
Are you sure you want to change the base?
Conversation
…namic register_info
I'd love to see benchmarks for chained / conditional .insert calls: to me that's the real alternative here in terms of performance. We can and should split those up from this PR: those are useful benchmarks for our later command batching work anyways. I still think we should proceed with this regardless of the slow perf, but it's good to be able to test / communicate what the alternatives are. |
I added a couple more benchmarks to compare with separate
These are supposed to simulate the insertion of an optional component, which is currently done with e.g. an
For completeness I also added a benchmark where an
|
Lovely; that's helpful justification, and those benches will be useful in the future. |
I think the |
Upon seeing #19560 I wonder if |
I think that making the common case pleasant is the way to go here. Most bundles will be static, so I like your current design. |
# Objective - Splitted off from #19491 - Make adding generated code to the `Bundle` derive macro easier - Fix a bug when multiple fields are `#[bundle(ignore)]` ## Solution - Instead of accumulating the code for each method in a different `Vec`, accumulate only the names of non-ignored fields and their types, then use `quote` to generate the code for each of them in the method body. - To fix the bug, change the code populating the `BundleFieldKind` to push only one of them per-field (previously each `#[bundle(ignore)]` resulted in pushing twice, once for the correct `BundleFieldKind::Ignore` and then again unconditionally for `BundleFieldKind::Component`) ## Testing - Added a regression test for the bug that was fixed
Objective
Bundle
forOption<T: Bundle>
Bundle
forBox<dyn Bundle>
andVec<Box<dyn Bundle>>
Self: Sized
bounds toBundle
trait methods #14879Option
bundles be faster than callinginsert
a second time#[bundle(ignore)]
fields were handled in the wrong waySolution
StaticBundle
(name bikesheddable) for usecases where the set of components of a bundle must be knowable without an instance of the bundle and switch functions that needed this aspect ofBundle
;&self
parameters toBundle
's methods to allow them to depend onself
's value;Bundle
s:ComponentId
sis_static
,is_bounded
andcache_key
methods onBundle
.Bundle
forOption<T: Bundle>
as a bounded bundle (i.e. withis_static = false
,is_bounded = true
and a cache key depending on whether it isSome
orNone
);Bundle
dyn-compatible and implementBundle
forBox<dyn Bundle>
where Self: Sized
and by introducing a couple of new dyn-compatible automatically-implemented supertraits,BundleDyn
andBundleEffectDyn
.#[bundle(dynamic)]
attribute for theBundle
derive macro to opt-out of derivingStaticBundle
andBundleFromComponents
BundleFromComponents
could theoretically be implemented for bounded but non-static bundles, but it seems tricky and I decided to leave it out from this PRTesting
Bundle
comes with its own tests incrates/bevy_ecs/src/bundle.rs
Showcase