Skip to content

Add index key for entities to improve use case performance #703

@damody

Description

@damody

Description

Add API can set key for entities, and use the key fast find entities
"specs::prelude::WorldExt" add function
fn find_entities(&self, key: T) -> Read
and add
fn create_entity_by_key(&mut self, key: T) -> EntityBuilder

Motivation

In open source game "veloren"
I usually see the code.

let entity_opt = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
                .join()
                .find(|(_, player)| player.alias == player_alias)
                .map(|(entity, _)| entity);

Basically, any query from player will loop all entities to find alias equal query name.
If ecs has 10000 players. the design include performance bottleneck.

Drawbacks

  • Is it a breaking change?
    no.
  • Can it impact performance, learnability, etc?
    to improve performance for search specific entitie

Unresolved questions

I just learn this project. I think author group will give me a best solution.


Please indicate here if you'd like to work on this ticket once it's been approved. Feel free to delete this section if not.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions