-
Notifications
You must be signed in to change notification settings - Fork 737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arsenal - Improve performance of loadout verification #9316
Arsenal - Improve performance of loadout verification #9316
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 _nullItemsList Arrays 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 _nullItemsList I'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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 _x
on 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_weaponCheck
and others.Optimization 4: Change use of
pushBackUnique
to combopushBack
andarrayIntersect
as 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
_containerItems
array 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}
.