--- a/rts/Sim/Units/Scripts/CobThread.cpp +++ b/rts/Sim/Units/Scripts/CobThread.cpp @@ -3,6 +3,8 @@ #include "CobThread.h" +#include + #include "CobDeferredCallin.h" #include "CobFile.h" #include "CobInstance.h" @@ -227,12 +229,14 @@ } } -#if 0 -#define GET_LONG_PC() (cobFile->code[pc++]) -#else -// mantis #5981 -#define GET_LONG_PC() (cobFile->code.at(pc++)) -#endif +// mantis #5981: every code read is range-checked and throws std::out_of_range like vector::at. +// WebBAR (parity plan M5, EB3): the code vector never changes size while a thread runs (CALL only +// rewrites one opcode in place), so the interpreter reads it through a pointer and size taken once per +// entry (COB_CODE_VIEW) instead of reloading the vector through cobFile around every call. Same values, +// same checks, same exception; mirrored in the native reference. +[[noreturn]] static void CobCodeOutOfRange() { throw std::out_of_range("COB code index out of range"); } +#define COB_CODE_VIEW() const int* const codeData = cobFile->code.data(); const size_t codeSize = cobFile->code.size() +#define GET_LONG_PC() ((static_cast(pc) < codeSize) ? codeData[pc++] : (++pc, CobCodeOutOfRange(), 0)) bool CCobThread::Tick() { @@ -246,6 +250,7 @@ state = Run; + COB_CODE_VIEW(); int r1, r2, r3, r4, r5, r6; while (state == Run) { @@ -772,6 +777,7 @@ void CCobThread::DeferredCall(bool synced) { + COB_CODE_VIEW(); const int r1 = GET_LONG_PC(); // script id const int r2 = GET_LONG_PC(); // arg count @@ -803,6 +809,7 @@ void CCobThread::LuaCall() { RECOIL_DETAILED_TRACY_ZONE; + COB_CODE_VIEW(); const int r1 = GET_LONG_PC(); // script id const int r2 = GET_LONG_PC(); // arg count --- a/rts/Sim/Units/Scripts/UnitScript.cpp +++ b/rts/Sim/Units/Scripts/UnitScript.cpp @@ -234,13 +234,17 @@ spring::VectorEraseIfAll(anims, [](const auto& ai) { return ai.done; }); #if 1 // BFS pass - std::deque> q; - q.push_front({ rootPiece, Transform{} }); - - while (!q.empty()) { + // WebBAR (parity plan M5, EB3): a per-thread queue reused across units and frames (FIFO by index) + // instead of a std::deque per unit per frame; this runs for every animating unit on the thread pool, + // and the deque's block allocations went through the shared allocator lock. Same visiting order and + // the same transforms, so results are unchanged; mirrored in the native reference. + static thread_local std::vector> q; + q.clear(); + q.push_back({ rootPiece, Transform{} }); + + for (size_t head = 0; head < q.size(); ++head) { // copy - auto [lmp, pTra] = q.front(); - q.pop_front(); + auto [lmp, pTra] = q[head]; if (lmp->GetDirty()) { lmp->SetDirtyRaw(false);