From 8971c25418565778d82e9d142675c718ae56b1d8 Mon Sep 17 00:00:00 2001 From: CanerKaraca23 <37447503+CanerKaraca23@users.noreply.github.com> Date: Sat, 4 Apr 2026 10:55:05 +0000 Subject: [PATCH 1/2] perf: replace std::unordered_map with flat array for PedColors state Moves the temporary render color storage from a global std::unordered_map keyed by CPed pointers to the struct-managed PedData. This completely avoids O(N) heap allocations resulting from hash bucket insertions and improves lookup speed to O(1) via the fast data extender pool. Previous map implementation also resulted in an implicit memory leak as map entries were `.clear()`ed rather than `.erase()`d. --- src/features/pedcols.cpp | 8 ++++---- src/features/pedcols.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/features/pedcols.cpp b/src/features/pedcols.cpp index 6a11849e..6768f228 100755 --- a/src/features/pedcols.cpp +++ b/src/features/pedcols.cpp @@ -9,7 +9,6 @@ using namespace plugin; #define RwRGBAGetRGB(a) (*(DWORD *)&(a) & 0xFFFFFF) -std::unordered_map>> store; void PedColors::SetEditableMaterials(RpClump *pClump) { RpClumpForAllAtomics(pClump, [](RpAtomic * pAtomic, void *data) { @@ -35,7 +34,7 @@ void PedColors::SetEditableMaterials(RpClump *pClump) { default: return pMaterial; } - store[PedColors::m_pCurrentPed].push_back(std::make_pair(&pMaterial->color, *reinterpret_cast(&pMaterial->color))); + data.m_OriginalColors.push_back(std::make_pair(&pMaterial->color, *reinterpret_cast(&pMaterial->color))); pMaterial->color.red = data.m_Colors[idx].r; pMaterial->color.green = data.m_Colors[idx].g; pMaterial->color.blue = data.m_Colors[idx].b; @@ -105,9 +104,10 @@ void PedColors::Init() { }; Events::pedRenderEvent.after += [](CPed *pPed) { - for (auto &e : store[pPed]) { + auto &data = PedColors::m_PedData.Get(pPed); + for (auto &e : data.m_OriginalColors) { *static_cast(e.first) = e.second; } - store[pPed].clear(); + data.m_OriginalColors.clear(); }; } \ No newline at end of file diff --git a/src/features/pedcols.h b/src/features/pedcols.h index 533ff503..eff2305e 100755 --- a/src/features/pedcols.h +++ b/src/features/pedcols.h @@ -14,6 +14,7 @@ class PedData { public: std::vector materials; std::vector m_Colors; + std::vector> m_OriginalColors; bool m_bUsingPedCols = false; bool m_bInitialized = false; int randId = -1; From 6796b84a5a05ffdf3dbfa153271d799e7d4775bd Mon Sep 17 00:00:00 2001 From: CanerKaraca23 <37447503+CanerKaraca23@users.noreply.github.com> Date: Sat, 4 Apr 2026 11:27:41 +0000 Subject: [PATCH 2/2] perf: replace std::unordered_map with flat array for PedColors state Moves the temporary render color storage from a global std::unordered_map keyed by CPed pointers to the struct-managed PedData. This completely avoids O(N) heap allocations resulting from hash bucket insertions and improves lookup speed to O(1) via the fast data extender pool. Previous map implementation also resulted in an implicit memory leak as map entries were `.clear()`ed rather than `.erase()`d.