diff --git a/README.md b/README.md index 0a2f4b3..1a3b005 100644 --- a/README.md +++ b/README.md @@ -45,12 +45,14 @@ AMD Ryzen 9 3900X 12-Core Processor 3.80 GHz Ran in Release mode on Windows x64 OS. ``` -100k paths took: 312.3261ms; time per call: 3.123µs -100k paths took: 313.0271ms; time per call: 3.13µs -100k paths took: 310.554ms; time per call: 3.105µs -100k paths took: 312.095ms; time per call: 3.12µs -100k paths took: 312.5054ms; time per call: 3.125µs -100k paths took: 315.6638ms; time per call: 3.156µs +100k paths took: 279.3573ms; time per call: 2.793µs +100k paths took: 280.2238ms; time per call: 2.802µs +100k paths took: 281.206ms; time per call: 2.812µs +100k paths took: 278.8223ms; time per call: 2.788µs +100k paths took: 277.9747ms; time per call: 2.779µs +100k paths took: 279.5909ms; time per call: 2.795µs +100k paths took: 277.8473ms; time per call: 2.778µs +100k paths took: 281.0326ms; time per call: 2.81µs ``` ### Rust (WebAssembly): @@ -61,13 +63,14 @@ This typically takes about 850ms on average in a real world scenario tested on a server also using TypeScript. ``` -100k paths took: 711ms; time per call: 7.11µs -100k paths took: 709ms; time per call: 7.09µs -100k paths took: 707ms; time per call: 7.07µs -100k paths took: 714ms; time per call: 7.14µs -100k paths took: 707ms; time per call: 7.07µs -100k paths took: 715ms; time per call: 7.15µs -100k paths took: 712ms; time per call: 7.12µs +100k paths took: 703ms; time per call: 7.03µs +100k paths took: 702ms; time per call: 7.02µs +100k paths took: 701ms; time per call: 7.01µs +100k paths took: 702ms; time per call: 7.02µs +100k paths took: 699ms; time per call: 6.99µs +100k paths took: 705ms; time per call: 7.05µs +100k paths took: 701ms; time per call: 7.01µs +100k paths took: 702ms; time per call: 7.02µs ``` ### AssemblyScript (WebAssembly): diff --git a/src/lib.rs b/src/lib.rs index 6c6fdd4..bf753c3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,8 +20,8 @@ use crate::rsmod::reach_strategy::ReachStrategy; pub mod rsmod; // alloc on the heap for the wasm module globally. -static mut COLLISION_FLAGS: Lazy = Lazy::new(|| CollisionFlagMap::new()); -static mut PATHFINDER: Lazy = Lazy::new(|| PathFinder::new()); +static mut COLLISION_FLAGS: Lazy = Lazy::new(CollisionFlagMap::new); +static mut PATHFINDER: Lazy = Lazy::new(PathFinder::new); #[wasm_bindgen] pub unsafe fn findPath( diff --git a/src/rsmod/collision/collision.rs b/src/rsmod/collision/collision.rs index ea86136..9da6ba4 100644 --- a/src/rsmod/collision/collision.rs +++ b/src/rsmod/collision/collision.rs @@ -2,7 +2,7 @@ use crate::rsmod::collision_flag::CollisionFlag; #[derive(Clone)] pub struct CollisionFlagMap { - pub flags: Vec>>, + pub flags: Vec>>, } impl CollisionFlagMap { @@ -65,10 +65,10 @@ impl CollisionFlagMap { } #[inline(always)] - unsafe fn allocate_if_absent_return(&mut self, zone_idx: usize) -> &mut Vec { - return (*self.flags.as_mut_ptr().add(zone_idx)).get_or_insert_with(|| { - vec![CollisionFlag::OPEN as u32; CollisionFlagMap::ZONE_TILE_COUNT] - }); + unsafe fn allocate_if_absent_return(&mut self, zone_idx: usize) -> &mut [u32; 64] { + return (*self.flags.as_mut_ptr().add(zone_idx)).get_or_insert(Box::new( + [CollisionFlag::OPEN as u32; CollisionFlagMap::ZONE_TILE_COUNT], + )); } #[rustfmt::skip]