Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Reduce allocations in horizontal_water_movement system #927

Open
alice-i-cecile opened this issue May 17, 2023 · 1 comment
Open

Reduce allocations in horizontal_water_movement system #927

alice-i-cecile opened this issue May 17, 2023 · 1 comment
Labels
performance Code go brrr
Milestone

Comments

@alice-i-cecile
Copy link
Contributor

There are a large number of unnecessary allocations in the system, primarily in the addItion_map, removal_map and flow_map hashmaps and the hashmap returned by proposed lateral flow to neighbors.

Instead, we should add:

/// Cache of water to be added and removed from each tile during [`horizontal_water_movement`].
///
/// This is for performance reasons, as it allows us to reduce allocations by reusing the same space.
#[derive(Component, Default, Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
pub struct LateralWaterCache {
    /// The amount of water to be added to each tile.
    incoming: Volume,
    /// The amount of water to be added to each neighbor.
    outgoing: [Volume; 6],
}

to the WaterBundle.

Then, this should be mutated in place.

@alice-i-cecile alice-i-cecile added the performance Code go brrr label May 17, 2023
@alice-i-cecile alice-i-cecile added this to the Scaling Up milestone May 17, 2023
@alice-i-cecile
Copy link
Contributor Author

This should probably wait on #905, as a very similar system is needed there for signal propagation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
performance Code go brrr
Projects
None yet
Development

No branches or pull requests

1 participant