bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Make the pointers in Fetch impls unions

Open james7132 opened this issue 3 years ago • 2 comments

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]

james7132 avatar Jun 23 '22 21:06 james7132

This was discussed on discord at https://discord.com/channels/691052431525675048/749335865876021248/989568732449865809

nicopap avatar Jun 24 '22 07:06 nicopap

Some suggested changes https://github.com/james7132/bevy/pull/4

nicopap avatar Jun 24 '22 11:06 nicopap