Page MenuHomeFeedback Tracker

[Improvement]: of '["Preload"] call BIS_fnc_arsenal'
New, NormalPublic

Description

Good day.
We've found out that this block inside "Init" case of BIS_fnc_arsenal is actually quite heavy on performance and with several mods enabled can freeze the arsenal opening process and the entire game with it for several seconds, as it is called in an unscheduled environment.
It would be nice to move it to "Preload" block so that it could be spawned in scheduled and do its magic without freezing the game. We suggest "Preload" case because it is actually a one-time preload of config files and their conversion, so it seems logic and clean.

The code block is following:

//--- Load stats
if (isnil {uinamespace getvariable "BIS_fnc_arsenal_weaponStats"}) then {
    uinamespace setvariable [
        "BIS_fnc_arsenal_weaponStats",
        [
            ("getnumber (_x >> 'scope') == 2 && getnumber (_x >> 'type') < 5") configclasses (configfile >> "cfgweapons"),
            STATS_WEAPONS
        ] call bis_fnc_configExtremes
    ];
};
if (isnil {uinamespace getvariable "BIS_fnc_arsenal_equipmentStats"}) then {
    _statsEquipment = [
        ("getnumber (_x >> 'scope') == 2 && getnumber (_x >> 'itemInfo' >> 'type') in [605,701,801]") configclasses (configfile >> "cfgweapons"),
        STATS_EQUIPMENT
    ] call bis_fnc_configExtremes;
    _statsBackpacks = [
        ("getnumber (_x >> 'scope') == 2 && getnumber (_x >> 'isBackpack') == 1") configclasses (configfile >> "cfgvehicles"),
        STATS_EQUIPMENT
    ] call bis_fnc_configExtremes;

    _statsEquipmentMin = _statsEquipment select 0;
    _statsEquipmentMax = _statsEquipment select 1;
    _statsBackpacksMin = _statsBackpacks select 0;
    _statsBackpacksMax = _statsBackpacks select 1;
    for "_i" from 2 to 3 do { //--- Ignore backpack armor and passThrough, has no effect
        _statsEquipmentMin set [_i,(_statsEquipmentMin select _i) min (_statsBackpacksMin select _i)];
        _statsEquipmentMax set [_i,(_statsEquipmentMax select _i) max (_statsBackpacksMax select _i)];
    };

    uinamespace setvariable ["BIS_fnc_arsenal_equipmentStats",[_statsEquipmentMin,_statsEquipmentMax]];
};

The example of our solution to mitigate this not being a part of 'Preload' (plus some minor optimizations):
https://gist.github.com/Asmo1Asmo1/f44bcfe9bf57f87145d0eded94a485ed

Thank you.

Details

Severity
Minor
Resolution
Open
Reproducibility
N/A
Operating System
Windows 10 x64
Category
Scripting

Event Timeline

Asmo created this task.May 7 2023, 5:25 AM