bevy
bevy copied to clipboard
Make the pointers in Fetch impls unions
Objective
Every Fetch struct initializes pointers for both storages, even though only one is ever really used. This both makes the struct bigger, and adds a miniscule amount of overhead when initializing a Fetch as it needs to zero out the unused Fetch impl.
Solution
Extend #4800. Add a compile-time discriminated union called StorageSwitch which is a debug-build checked union of different ways a Fetch could represent a pointer to the respective storage.
As sparse sets always have a reference populated when making a fetch. They're no longer wrapped in an Option, and do not need any unwrapping.
This can be done (more) safely if GATs was stablized, but it seems like rust-lang/rust#96709 may be stalled for the foreseeable future.
As this is based on #4800, this won't come out of draft until some form of that PR is merged.
Co-Authored-By: Boxy [email protected]
This was discussed on discord at https://discord.com/channels/691052431525675048/749335865876021248/989568732449865809
Some suggested changes https://github.com/james7132/bevy/pull/4