Fix performance regressions: remove TIER0, consolidate scratchpads, remove Arc trap

Key fixes based on benchmark analysis:
1. Remove TIER0 Vec-based pathfinding - O(N) linear scan was slower than FxHashMap for typical path lengths
2. Consolidate scratchpads into single AStarScratchpad struct - eliminates nested RefCell borrow overhead
3. Remove Arc wrapper from TileMap - eliminated Copy-on-Write trap causing 63ms stutters
4. Replace AHashMap with FxHashMap - FxHash is faster for small integer keys like IVec3
5. Simplify tier logic - single pathfinding function with scratchpad reuse

Benchmark analysis showed:
- Original: 1.95 µs/node, P99 1.1ms, Max 5ms
- TIER0/TIER1 regression: 2.89 µs/node (+48%), P99 5ms (+348%)
- Root causes: Vec linear scan in TIER0, nested RefCell borrows, Arc::make_mut CoW

This should restore and improve performance by using simple FxHashMap scratchpad for all paths.
This commit is contained in:
2026-03-18 15:30:48 +00:00
parent 466a20700a
commit 367ab26d5e
3 changed files with 246 additions and 1346 deletions
+3 -9
View File
@@ -4,12 +4,6 @@ pub const TILE_SIZE: f32 = TILE_PIXELS as f32 * PIXEL_RATIO;
pub const ITILE_SIZE: i32 = TILE_SIZE as i32;
pub const SEED: u32 = 420;
// Pathfinding tier thresholds (in tiles)
pub const PATHFINDER_TIER0_MAX_TILES: i32 = 10; // Very short paths: Vec-based
pub const PATHFINDER_TIER1_MAX_TILES: i32 = 30; // Short paths: AHashMap scratchpad
pub const PATHFINDER_TIER2_MAX_TILES: i32 = 100; // Medium paths: AHashMap scratchpad
// TIER3: > 100 tiles → Chunk waypoints + async
// Pathfinding configuration
pub const PATHFINDER_MAX_NODES: usize = 5000; // Max nodes before partial path
pub const PATHFINDER_ASYNC_THRESHOLD_TILES: i32 = 150; // Start async for very long paths
pub const PATHFINDER_SHORT_PATH_MAX_TILES: i32 = 100;
pub const PATHFINDER_MAX_NODES: usize = 5000;
pub const PATHFINDER_WAYPOINT_THRESHOLD_TILES: i32 = 100;