From f2237c5531a66602e2453fa81d1fed965d304c66 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 29 Mar 2026 19:51:26 -0700 Subject: [PATCH] perf: switch 3 spawn queues from vector to deque MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pendingPlayerSpawns_, deferredEquipmentQueue_, and pendingGameObjectSpawns_ are consumed from the front via erase(begin()), which is O(n) on vector (shifts all elements). With many spawns queued (entering a city), this made the processing loop O(n²). deque supports O(1) front erasure. pendingCreatureSpawns_ already used deque. --- include/core/application.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/core/application.hpp b/include/core/application.hpp index 28116152..de5280ff 100644 --- a/include/core/application.hpp +++ b/include/core/application.hpp @@ -344,7 +344,8 @@ private: std::unordered_map onlinePlayerAppearance_; std::unordered_map, std::array>> pendingOnlinePlayerEquipment_; // Deferred equipment compositing queue — processes max 1 per frame to avoid stutter - std::vector, std::array>>> deferredEquipmentQueue_; + // deque: consumed from front in a loop; vector::erase(begin) would be O(n²). + std::deque, std::array>>> deferredEquipmentQueue_; void processDeferredEquipmentQueue(); // Async equipment texture pre-decode: BLP decode on background thread, composite on main thread struct PreparedEquipmentUpdate { @@ -402,7 +403,7 @@ private: uint8_t facialFeatures; float x, y, z, orientation; }; - std::vector pendingPlayerSpawns_; + std::deque pendingPlayerSpawns_; std::unordered_set pendingPlayerSpawnGuids_; void processPlayerSpawnQueue(); std::unordered_set creaturePermanentFailureGuids_; @@ -415,7 +416,7 @@ private: float x, y, z, orientation; float scale = 1.0f; }; - std::vector pendingGameObjectSpawns_; + std::deque pendingGameObjectSpawns_; void processGameObjectSpawnQueue(); // Async WMO loading for game objects (file I/O + parse on background thread)