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

Add a safe, typed equivalent to EntityWorldMut::insert_by_ids #15444

Closed
alice-i-cecile opened this issue Sep 26, 2024 · 1 comment
Closed

Add a safe, typed equivalent to EntityWorldMut::insert_by_ids #15444

alice-i-cecile opened this issue Sep 26, 2024 · 1 comment
Labels
A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times S-Duplicate This issue or PR already exists

Comments

@alice-i-cecile
Copy link
Member

I am seeing bad performance upon receiving a lot of components from game server that need to be added to entity for the first time for hundreds of entities.

As there could be multiple possible combinations of components for entity I can not use bundles.

Pseudocode:

for entity_data in entities_data_from_server {
     let entity = get_entity_or_spawn(...., entity_data.entity_id);
     for component in entity_data.components {
         match component {
                ComponentA(comp) => { entity.insert(comp); }     
                ComponentB(comp) => { entity.insert(comp); }         
               ....
         }
    }
}

As much as I understand:
Each new component insert (directly to world or through command) results in entity being moved from one archetype to another. It would be good if all these operations could be grouped together in dynamic ComponentSet data structure that could be inserted into entity in one operation. In this case no unneeded intermediate archetypes would be initialized, no redundant data moves of entity between different archetypes would be needed.

It looks like something similar can be done with unsafe: https://docs.rs/bevy/latest/bevy/ecs/prelude/struct.EntityWorldMut.html#method.insert_by_ids
It would be nice if there would be a safe variant that is easy to use or bundles with optional components (#2157 (comment)) .

Originally posted by @PPakalns in #3227 (comment)

@alice-i-cecile
Copy link
Member Author

Actually, this is a duplicate of #2693, and a workaround for #5074.

@alice-i-cecile alice-i-cecile closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2024
@alice-i-cecile alice-i-cecile added S-Duplicate This issue or PR already exists A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times labels Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times S-Duplicate This issue or PR already exists
Projects
None yet
Development

No branches or pull requests

1 participant