-
Notifications
You must be signed in to change notification settings - Fork 149
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
Common - Optimize CBA_fnc_compatibleMagazines
#1585
Common - Optimize CBA_fnc_compatibleMagazines
#1585
Conversation
If it's cached anyway, why bother dicking around with dictionaries when building up the arrays the first time? This getOrDefaultCall syntax is an abomination. I like the namespace -> HashMap part though. Any benchmark before after? |
Because it's faster. You don't have to use
The reason I used that is because it's faster.
I will run some tonight and report the numbers, but from the limited testing I ran it's always faster. |
Something I have just thought of: I could make the hashmap stored in |
No, that can be abused. |
I tested with In a first test, I ran only the code from ["arifle_AK12_F"] call _oldCode; // 0.70 ms
["arifle_AK12_F"] call _newCode; // 0.20 ms I reran the first test, but with this time to get all magazines. However, these do call ["arifle_AK12_F", true] call _oldCode; // 0.25 ms
["arifle_AK12_F", true] call _newCode; // 0.0475 ms So for getting magazines the first time, the new code is significantly faster. For conventional usage: "arifle_AK12_F" call CBA_fnc_compatibleMagazines // Old, 0.0070 ms
"arifle_AK12_F" call CBA_fnc_compatibleMagazines // New, 0.0067 ms
["arifle_AK12_F", true] call CBA_fnc_compatibleMagazines // Old, 0.0073 ms
["arifle_AK12_F", true] call CBA_fnc_compatibleMagazines // New, 0.0070 ms
// Much smaller modset:
"arifle_AK12_F" call CBA_fnc_compatibleMagazines // Old, 0.0051 ms
"arifle_AK12_F" call CBA_fnc_compatibleMagazines // New, 0.0046 ms
["arifle_AK12_F", true] call CBA_fnc_compatibleMagazines // Old, 0.0053 ms
["arifle_AK12_F", true] call CBA_fnc_compatibleMagazines // New, 0.0048 ms
How so? How is having a |
You can put compileFinal'd function in there before it is populated by an actual value and therefore can cause scripts to fail unexpectedly. missionNamespace is cleared at mission start, therefore can't carry over values from, e.g. the editor. |
That's irrelevant then though. .X milliseconds once per mission is a meaningless improvement. Readability trumps premature optimization here. The relevant result is pretty much the same. ~5-10% improvement. Not worth it. |
If you have a mod loaded that loads anything in If there is a will, there is a way. If people want to break something, they will be able to. You could just as easily break
How is it irrevelant, meaningless or not worth it? Arma runs like a piece of shit. Any improvement should be a welcome one.
I seriously fail to see how the readability of the code has been compromised. Just when comparing the difference side by side you can see it's not fundamentally different. "Premature" really rubs me the wrong way. What is the premature part? |
Errors can be ignored. The failed script however may give the player an ingame advantage. Yes, malicious intend. I have reported bugs of ui namespace abuse to BI multiple times in the past, and they have all fixed them. Even got me two extra copies of APEX as reward, because some of these enabled arbitrary code execution. It's hard to utilize ui namespace without introducing exploits. It's not worth it to work around these exploits when the potential gain is a laughable < 0.001 seconds per mission start per weapon. That's what makes any of this premature.
"Premature optimization" is a phrase coined by Donald Knuth. The cache itself is properly utilized optimization. It made using the function essentially free. I still like the part where you rewrite it to use the native HashMap instead of the custom CBA namespace. I have nothing against modernizing old code. |
Ultimately, what does this mean? What changes are going to be accepted besides switching |
If it were up to me, that + the function header fixes.
nay, not worth it |
If nobody else says anything in the near future, I'll go with what you said. |
Seeing as nobody has said anything, going ahead with your suggestion. |
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.
lgtm
CBA_fnc_compatibleMagazines
When merged this pull request will:
CBA_fnc_compatibleItems
#1558.