Arsenal - Improve performance of loadout verification#9316
Arsenal - Improve performance of loadout verification#9316LinkIsGrim merged 19 commits intoacemod:masterfrom
Conversation
johnb432
left a comment
There was a problem hiding this comment.
Mostly formatting changes in my review, but also some a very minor performance improvement suggestion.
Are you sure about this? I had the impression the opposite was true. |
|
Yeah, that is true IIRC. With |
I was under the assumption that creating a hashmap/setting a key is slower than using arrays, and I was specifically avoiding using |
It really depends on what is being done: Hashmaps will be roughly 80-90x faster if there are loads of different entries, like here: private _nullItemsList = createHashMap;
for "_i" from 1 to 10000 do {
_nullItemsList set [_i, nil];
};
keys _nullItemsListArrays will be 2x faster if there are loads of the same entry: private _nullItemsList = [];
for "_i" from 1 to 10000 do {
_nullItemsList pushback 1; // Not _i like in example above!
};
_nullItemsList arrayIntersect _nullItemsListI'm guessing in this application it's more of the first case, however in game it doesn't make a measurable difference. If a loadout were to have all items available |
Updated my suggestions @LinkIsGrim |
…douts-performance1
…com/Salluci/ACE3 into arsenal-verifyLoadouts-performance2
|
LinkIsGrim@e5950f2 switches to a single iteration through the loadout array (turning everything into configCase, checking for null and availability all at once). Output for the same test loadout: Readability isn't the best, though. |
…douts-performance1
Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
johnb432
left a comment
There was a problem hiding this comment.
I've tested it, but I feel it could do with some more by others.
When merged this pull request will:
Switched to single iteration through the loadout array. See previous optimizations below.
Old
Optimization 1: Add items to nullItemsList along with configCase changes, since we know that `configName _x == ""` means the class doesn't exist anywhere.
Optimization 2: Replace null items with empty string directly when changing loadout contents to configCase. This removes the need to check for
isClass _xon the second iteration through the loadout.Optimization 3: Check all classnames against
GVAR(virtualItemsFlatAll)instead of categories, since hashmap lookup time is constant. This allowed for removing the index checking in_fnc_weaponCheckand others.Optimization 4: Change use of
pushBackUniqueto combopushBackandarrayIntersectas that is faster in most cases now, particularly with large arrays.Optimization 5: Switch use of count of unavailable/null items for checking the lists against a default value in relevant places.
Optimization 6: Replaced some loop logic (assignedItems now uses forEach, and container item checking was changed to use the
_containerItemsarray already defined in_x params).Optimization 7: Due to all of the above, config lookups and some variable assignments could be removed.
To make this work, the unavailable items list needs to be checked against [""]. Otherwise array modification or explicit checking for
_x != ""would be needed for everything, which would reduce performance gain.End result, loading just CBA and ACE and checking against a full arsenal, is a 13% improvement:
Loadout verification is already pretty fast now thanks to hashmaps but it's still the part of the arsenal where a user is most likely to notice stuttering or hang ups, particularly with large loadout lists and loadouts with many different item types.
Possible issues:
FUNC(verifyLoadout)? It's not public, though.IMPORTANT
Component - Add|Fix|Improve|Change|Make|Remove {changes}.