SCMD_LOADSPOFFS inefficient code (script interpreter) #869
Labels
context: code
fixing/improving existing code: refactor, optimise, tidy...
context: performance
related to improving program speed or lowering system requirements
context: script vm
type: enhancement
a suggestion or necessity to have something improved
As noted by @rofl0r earlier, SCMD_LOADSPOFFS implementation became very inefficient in comparison to the original script VM.
Original code: https://github.com/adventuregamestudio/ags/blob/legacy/Common/csrun.cpp#L1499
New code is implemented as ccInstance::GetStackPtrOffsetRw function:
ags/Engine/script/cc_instance.cpp
Lines 2261 to 2278 in 5adc343
as you may notice, instead of simply "jumping" into requested address the new code parses the stack checking it entry by entry until accumulating necessary offset.
TBH I don't remember all details now, but I think the main reason for this function was that old stack was implemented as a plain sequence of bytes, while the new stack is implemented as an array of RuntimeScriptValue objects, which in turn may contain pointers to larger data (such as arrays) allocated separately. The new code also stores separate Ptr as an address of the object's "head" and extra offset in IValue.
You may also notice the "64-bit" fix in the legacy branch which did similar thing and maybe which I used as a reference too.
Given the above, I am not sure if it's easy to optimize this particular operation without changing some fundamental principles of how new interpreter works.
The text was updated successfully, but these errors were encountered: