mActiveLocalScripts is walked four times a frame (prune, stats, timers,
update) and inserted into only when an object becomes active, which is the
access pattern a contiguous container is for. A std::set pays red-black tree
pointer chasing on every one of those walks.
Hold a vector sorted by container address instead. Sorted rather than
unsorted because a duplicate entry would dispatch a container's handlers
twice; the ordering itself was never meaningful, since the set was ordered by
pointer address too.
Measured on the Path of the Incarnate save: Lua p50 3.489 -> 3.366 ms, -3.5%,
with all three treatment runs below all three control runs.
This only fixes the first of the three hops needed to reach a container: the
weak pointer is now sequential, but dereferencing it to the heap slot and
then to the container are still dependent misses. Resolving the list into
dense pointers once per frame is blocked on lifetime, since running timers
and update handlers can deactivate an object mid-walk and re-resolving is
exactly the protection that would be discarded.
statsNextFrame walked every script in a container every frame purely to
multiply each running average by a decay constant, whether or not the script
had run. With 701 active containers that walk is pure overhead for scripts
that were idle.
The averaging is a geometric decay, so the frames a script sat out fold into
a single power. Record the frame each average was last written and apply the
missing decay when it is next written or read; the per-frame call then only
bumps a counter, and a frame costs the same whether a container holds one
script or a thousand.
Reading the stats deliberately does not write them back, so collectStats
stays const and the decay is applied for real by whoever writes next.
Implement sol_lua_push for ESM::RefId to automatically convert empty
RefIds to nil in Lua. This fixes cell.region and cell.worldSpaceId
returning empty strings, and applies the same pattern consistently
across all Lua bindings.
Removes LuaUtil::serializeRefId as it's no longer needed.
Fixes#8718
luamanagerimp still needs float frameDuration, and reordering a bunch of fields in the scene manager conflicted with changing the type of maxanisotropy.