robalo / mods

ASR stuff
GNU General Public License v2.0
23 stars 10 forks source link

perf opt fnc_showHideNVG #13

Closed dedmen closed 5 years ago

dedmen commented 5 years ago

This is a really controversial change.. Iterating through items _unit can end VERY badly.

Without a backpack: Old: 35.3315us New: 157.935us

With a backpack full of ACE bandages: Old: 2951.2us New: 170.588us

Old code scales up with amount of items in inventory. New code doesn't.

Alternative

private _items = (items _unit);
{ if (getText(configFile>>"CfgWeapons">>_x>>"simulation") == "NVGoggles") exitWith {_nvg = _x} } forEach (_items arrayIntersect _items);

Without backpack: 25.463us With backpack: 279.848us

Still scales up. But the effect at the few-items-in-inventory end isn't as dramatic.

Or another alternative. Make your own specialized variant of CBA_fnc_uniqueUnitItems

private _allItems = assignedItems _unit; 
_allItems append ((getItemCargo (uniformContainer _unit)) select 0); 
_allItems append ((getItemCargo (vestContainer _unit)) select 0); 
_allItems append ((getItemCargo (backpackContainer _unit)) select 0);

_allItems arrayIntersect _allItems

Using that instead of calling the CBA func: without backpack: 74.1513us with backpack: 123.623us

dedmen commented 5 years ago

Your change is a perf degradation as you are now making the configFile >> "CfgWeapons" lookup every iteration instead of just doing it once.

Removing assigned items won't make a big difference. But it of course makes logical sense if you want to exclude them.

robalo commented 5 years ago

thanks !