22e6d29ddcaae30631f42651e65fc98a90ebfa01
PROBLEM: Extreme lag with 100+ bots caused by SpatialGridManager issues: 1. DATA RACE BUG in GetGrid(): - Writing lastAccessTime under shared_lock using const_cast - Multiple threads writing same memory location concurrently = undefined behavior - Could cause crashes, memory corruption, or silent data corruption 2. PERFORMANCE ISSUE in GetGrid(): - Called thousands of times per second (100+ bots × multiple calls per update) - Each call: acquire shared_lock + chrono::steady_clock::now() - Unnecessary overhead for a keep-alive timestamp that's rarely checked 3. Same issues in UpdateGrid() and TouchGrid() SOLUTION: 1. GetGrid(): Remove lastAccessTime update entirely - This method is for READ-ONLY grid access - lastAccessTime is only used for cleanup of inactive grids - No need to update on every access 2. UpdateGrid(): Split into 3 phases - Phase 1: Get grid pointer under shared_lock (fast) - Phase 2: Update grid WITHOUT holding manager lock - Phase 3: Update lastAccessTime under exclusive lock 3. TouchGrid(): Use unique_lock (exclusive) for write operation - This method explicitly updates lastAccessTime - Must use exclusive lock for write operations IMPACT: - Eliminates ~1000+ chrono::now() calls per second - Fixes potential memory corruption from data race - Reduces lock contention on SpatialGridManager Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: luis <[email protected]>
WowCommunityProject
Blizzlike WowCommunity project
Languages
C++
89.3%
C
10.1%
CMake
0.4%