Skip to content
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

Empty structs / Tag components should not consume any memory #29

Closed
genaray opened this issue Dec 9, 2022 · 2 comments
Closed

Empty structs / Tag components should not consume any memory #29

genaray opened this issue Dec 9, 2022 · 2 comments
Labels
enhancement New feature or request postponed This feature was postponed to a later release.

Comments

@genaray
Copy link
Owner

genaray commented Dec 9, 2022

Tag components ( Empty structs ) do actually consume 1 byte per instance and are actually being allocated in each chunk.
Instead we could just ignore them, however this means that that some query like this...

world.Query(in desc, (ref Transform t, ref SomeTag tag) => {});

Would throw an exception since the entity is tagged with it, but since its a non allocated tag component it can not be acessed.
Debug.Assert could probably help here to avoid such errors.

@genaray genaray added the enhancement New feature or request label Dec 9, 2022
@genaray
Copy link
Owner Author

genaray commented Dec 16, 2022

Problem

This is actually a bit harder to solve, since it would require a totally different handling of certain API calls or a lot of different conditions to make sure a user does not "Set" or "Get" a tag component.

Different solution

Instead a different solution was picked, each tag component still allocates an array ( which still is very very cheap ), but those arrays are not part of the chunk size calculation. This way Transform, Rotation, AITag and Transform, Rotation will fit the same amount of entities into each chunk, regardless of the tag. Since the tag is not being acessed in queries, the speed is also optimal.

This solution is like the golden middle.

Partially solved in b56ec46

@genaray genaray added the postponed This feature was postponed to a later release. label Dec 16, 2022
@clibequilibrium
Copy link
Contributor

Tag components ( Empty structs ) do actually consume 1 byte per instance and are actually being allocated in each chunk. Instead we could just ignore them, however this means that that some query like this...

world.Query(in desc, (ref Transform t, ref SomeTag tag) => {});

Would throw an exception since the entity is tagged with it, but since its a non allocated tag component it can not be acessed. Debug.Assert could probably help here to avoid such errors.

flecs enforces Tags to have at least 1 field for example, int dummy; and it worked quite well for them. I see no issue with that either

@genaray genaray closed this as completed Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request postponed This feature was postponed to a later release.
Projects
Status: Done
Development

No branches or pull requests

2 participants