Closed sprunk closed 9 years ago
@GoogleFrog did a messy UnitPreDamaged() optimization, judge from that, and decide if you want it on all callins
That optimisation is unrelated to the removal of ipairs (it exists to prevent calling the event for gadgets that declare they aren't interested) and is not even messy. It could even be as tidy as all other call-ins if the initialisation stuff actually happened on initialisation instead of checking for the first run every time.
Replacing ipairs with normal iteration is still fairly tidy but even if it wasn't, gadget handler can afford to be messy if it helps gain performance.
I think you should run a test to determine the difference between ipairs and a manual iterator. I think tidyness is important for the gadget handler but I would also like to keep the difference between the basecontent handler and ours small. If there is no performance gain to be had with this change then I do not want it implemented.
About that, using normal iteration is faster, but only if the iterator is the most expensive part of a given loop. In other words, it only matters if the loop does 9001 iterations but has a cheap body. I experimented with it in my own code and never noticed a difference.
there won't be any way to prove this will work because there's no gadgetHandler or widgetHandler profiler.
According to https://springrts.com/wiki/Lua_Performance normal iteration is twice as fast. The overhead is comparatively small in most cases however.
There are some call-ins that tend to have cheap bodies and get called a lot and so could benefit from the reduced overhead (for example Allow*BuildStep).
Closing because any changes in the handlers are difficult to measure.
Apparently ipairs are expensive. Should that be changed to normal iteration or is keeping ipairs intended?