diff options
| author | mat <git@matdoes.dev> | 2026-01-04 20:48:08 +0930 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2026-01-04 20:48:08 +0930 |
| commit | 203d178dab15206a6c19b7e8063f9f397373b118 (patch) | |
| tree | bf1a4f2ae377629fe40cc8c110621e2d2e0c4f25 /azalea/src | |
| parent | 91fde2dbea41a07c261cd8b85ac4c851e993efc8 (diff) | |
| download | azalea-drasl-203d178dab15206a6c19b7e8063f9f397373b118.tar.xz | |
small pathfinder optimization by improving cache locality for cached_mining_costs
Diffstat (limited to 'azalea/src')
| -rw-r--r-- | azalea/src/pathfinder/world.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/azalea/src/pathfinder/world.rs b/azalea/src/pathfinder/world.rs index 980cda9a..819e4254 100644 --- a/azalea/src/pathfinder/world.rs +++ b/azalea/src/pathfinder/world.rs @@ -314,10 +314,7 @@ impl CachedWorld { let cached_mining_costs = unsafe { &mut *self.cached_mining_costs.get() }; // 20 bits total: // 8 bits for x, 4 bits for y, 8 bits for z - let hash_index = ((pos.x as usize & 0xff) << 12) - | ((pos.y as usize & 0xf) << 8) - | (pos.z as usize & 0xff); - debug_assert!(hash_index < 1048576); + let hash_index = Self::calculate_cached_mining_costs_index(pos); let &(cached_pos, potential_cost) = unsafe { cached_mining_costs.get_unchecked(hash_index) }; if cached_pos == pos { @@ -332,6 +329,16 @@ impl CachedWorld { cost } + fn calculate_cached_mining_costs_index(pos: RelBlockPos) -> usize { + // 20 bits total: + // 8 bits for x, 8 bits for z, 4 bits for y + let hash_index = ((pos.x as usize & 0xff) << 12) + | ((pos.z as usize & 0xff) << 4) + | (pos.y as usize & 0xf); + debug_assert!(hash_index < 1048576); + hash_index + } + fn uncached_cost_for_breaking_block( &self, pos: RelBlockPos, |
