Skip to content

Loading chunks overruns ticks by a lot due to the scheduler having a hard time with the number of entity types to try load #31

@ReCore-sys

Description

@ReCore-sys

Currently when a chunk is loaded a message is fired off that every single entity's loader system reads, then loads and iterates the chunk's entities to see if there are any to load of the type it is concerned with. This is great in theory, but ends up with a stupid amount of contention on the chunk's entity list. The way to solve this is by having a singular system for loading entities that loads the chunk once, iterates the entity list and dispatches off to a normal function for each type of entity. I didn't do this the first time around because I forgot how dashmap works and assumed being able to parallelize entity loading would be faster when in reality we could probably just do this with rayon or something. This will require changing some of the macro code though.
Anyway, we'd probably want something like this (ignore the terrible psudocode):

for message in load_chunk_messages {
    for (entity_data, entity_type) in world.get_chunk(message.coords).entities {
        if entity_type == Pig {
            load_pig(commands, entity_data);
        } else if entity_type == Cow {
            load_cow(commands, entity_data);
        ....
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingoptimizationSomething could be tuned up or optimized

    Type

    Projects

    Status

    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions