Closed Iridar closed 1 year ago
Just found this propagates to other mods as well, resulting in noticeable frame freezes.
This trace shows the use of 'TACTICALRULES.UnitHasActionsAvailable' from a mod (Select Soldier Icons Redux): The three spikes in frame time all involve calls to 'IsModInstalled'
Another fix without the need for every caller of IsModInstalled to remember to cache it, is to lazy cache any requested mod names:
this will fix all usages of IsModInstalled, also for 3rd party mods using it.
this will fix all usages of IsModInstalled, also for 3rd party mods using it.
IsModInstalled is not a globally implemented function. Meaning each mod that wants to do this check includes a copy of this function. It's not possible for LWOTC to change how it works in any other mod.
IsModInstalled is not a globally implemented function.
I see, that's my lack of Unreal(Script) knowledge :)
I see this snippet in some mods:
static function bool IsModInstalled(name X2DCIName)
{
local X2DownloadableContentInfo Mod;
foreach `ONLINEEVENTMGR.m_cachedDLCInfos (Mod)
{
if (Mod.Class.Name == X2DCIName)
{
return true;
}
}
return false;
}
Seems that CHL already has a cached list of dlc infos. might not even be worth caching at all, and just use this, since checking a list of let's say 1000 mods should not be noticeable (but again, do not know enough about UnrealScript to back that up).
This method cannot be used universally, unfortunately, because it checks specifically for X2DownloadableContentInfo script files, and any mod can include any number of these, potentially none, and their name is not set in stone the same way the mod name is.
LWOTC has a few
IsModInstalled()
checks, including in hot code, likeGetToHitAsTargetModifiers()
inX2Effect_SmokeFlankingCritProtection
.This is suboptimal to the point where it can cause stuttering in tactical, for example when switching between active units.
Relevant discord report.
The suggested solution is to do
IsModInstalled()
checks in OPTC or somewhere else similar, and cache the result of the check in a class variable, for example:And in OPTC:
The check can also be accelerated by adding
final
toIsModInstalled()
function definition.Ideally this kind of caching should be done to all instances of
IsModInstalled()
.The slowest part of the check seems to be
class'Helpers'.static.GetInstalledModNames()
. So the alternative universal solution is to cache its output into aconfig array<name>
, and using the cached array for any check that follows the first.