-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Reflect auto registration #15030
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?
Reflect auto registration #15030
Conversation
…atic registration
…omatic reflect registration functionality at compile time
Is this compared to the equivalent manual registration? Can / should we feature flag this for authors who particularly care? |
You added a new feature but didn't update the readme. Please run |
As far as I understand it, wasm-init works by exporting a bunch of symbols to final wasm and calling them from outside when |
All sizes are in KB as reported by
Update: Disregard that, I misunderstood how reflection works and missed registering type data. |
Automatic reflect registration registeres all reflect types within testing module. This creates multiple type registrations with the same type path, which breaks `ReflectDeserializer` in `bevy_reflect` tests.
Registering types on `AppTypeRegistry` creation breaks dynamic scene builder.
This comment was marked as outdated.
This comment was marked as outdated.
it would be interesting to benchmark compilation duration with this change to see the impact |
This reverts commit 2eb5d1b.
…t-auto-registration-staticlib
The generated |
Added support for platforms without inventory support (
All of these downsides are applicable only when using the |
…t-auto-registration
Objective
This PR adds automatic registration of non-generic types annotated with
#[derive(Reflect)]
.Manually registering all reflect types can be error-prone, failing to reflect during runtime if some type is not registered. #5781 fixed this for nested types, improving ergonomics of using reflection dramatically, but top-level types still need to be registered manually. This is especially painful when prototyping and using inspector to change values of components.
Fixes #3936.
Solution
Automatically register all types that derive Reflect. This works for all non-generic types, allowing users to just add
#[derive(Reflect)]
to any compatible type and not think about where to register it.Automatic registration can be opted-out of by adding
#[reflect(no_auto_register)]
reflect attribute to a type:Registration normally happens at app creation time, but
TypeRegistry
itself has a newregister_derived_types
method to register all collected types at any appropriate time:Testing
reflect
example and removing explicit type registration, both on native and onwasm32-unknown-unknown
.register_derived_types
Impact on startup time is negligible: <40ms on debug wasm build and <25ms on debug native build for 1614 registered types .
Wasm binary size comparison. All sizes are in KB as reported by
du
on the modifiedreflection
example.Considerations
While automatic type registration improves ergonomics quite a bit for projects that make heavy use of it, there are also some problems:
1000 simple structs with reflect wasm size comparison, no engine types