ussrlongbow 116 Posted October 14, 2016 While working on a function for UI interface, faced a strange performance drop. See the example:Snippet 1 disableSerialization; _index = 1; _display = uiNamespace getVariable "ADIS_MENU_DISPLAY"; // 2.5x faster than for _i from 1 to 8 .... (_display displayCtrl 66311) ctrlSetText ""; (_display displayCtrl 66312) ctrlSetText ""; (_display displayCtrl 66313) ctrlSetText ""; (_display displayCtrl 66314) ctrlSetText ""; (_display displayCtrl 66315) ctrlSetText ""; (_display displayCtrl 66316) ctrlSetText ""; (_display displayCtrl 66317) ctrlSetText ""; (_display displayCtrl 66318) ctrlSetText ""; Code performance shows 0.0176 ms on my PCSnippet 2 disableSerialization; _index = 1; _display = uiNamespace getVariable "ADIS_MENU_DISPLAY"; if (_index in [1,2,3,4,5,6,7,8]) then { (_display displayCtrl (66310 + _index)) ctrlSetText (format ["addons\longbow\adis\icons\s%1.paa",_index]); rwt_adis_selector_hidden = false; }; Performance is around 0.0172msWhat would I expect when I merge this two snippets? like this: disableSerialization; _index = 1; _display = uiNamespace getVariable "ADIS_MENU_DISPLAY"; (_display displayCtrl 66311) ctrlSetText ""; (_display displayCtrl 66312) ctrlSetText ""; (_display displayCtrl 66313) ctrlSetText ""; (_display displayCtrl 66314) ctrlSetText ""; (_display displayCtrl 66315) ctrlSetText ""; (_display displayCtrl 66316) ctrlSetText ""; (_display displayCtrl 66317) ctrlSetText ""; (_display displayCtrl 66318) ctrlSetText ""; if (_index in [1,2,3,4,5,6,7,8]) then { (_display displayCtrl (66310 + _index)) ctrlSetText (format ["addons\longbow\adis\icons\s%1.paa",_index]); rwt_adis_selector_hidden = false; }; Interested? Code performance shows 0.2 ms, ~5x performance drop, can anyone explain why it happens? Share this post Link to post Share on other sites
ussrlongbow 116 Posted October 14, 2016 fast update, reorganized a function a bit, getting the expected 0.04ms result, with this code disableSerialization; _index = 1; _display = uiNamespace getVariable "ADIS_MENU_DISPLAY"; _arr = [1,2,3,4,5,6,7,8]; if (_index in _arr) then { _arr deleteAt (_index - 1); (_display displayCtrl (66310 + _index)) ctrlSetText (format ["addons\longbow\adis\icons\s%1.paa",_index]); _arr apply { (_display displayCtrl 66310 + _x) ctrlSetText ""; }; }; but original question is still open, why performance drop happens in the first place. Share this post Link to post Share on other sites
gc8 981 Posted October 14, 2016 disableSerialization; _index = 1; _display = uiNamespace getVariable "ADIS_MENU_DISPLAY"; (_display displayCtrl 66311) ctrlSetText ""; (_display displayCtrl 66312) ctrlSetText ""; (_display displayCtrl 66313) ctrlSetText ""; (_display displayCtrl 66314) ctrlSetText ""; (_display displayCtrl 66315) ctrlSetText ""; (_display displayCtrl 66316) ctrlSetText ""; (_display displayCtrl 66317) ctrlSetText ""; (_display displayCtrl 66318) ctrlSetText ""; if (_index in [1,2,3,4,5,6,7,8]) then { (_display displayCtrl (66310 + _index)) ctrlSetText (format ["addons\longbow\adis\icons\s%1.paa",_index]); rwt_adis_selector_hidden = false; }; Interested? Code performance shows 0.2 ms, ~5x performance drop, can anyone explain why it happens? it could be the line where you are loading image. HD access is pretty slow. Share this post Link to post Share on other sites
Guest Posted October 14, 2016 Yeah it could be the problem actually. In the second snippet you let him keep up running the script without applying another image directly with the ctrlSetText "". Anyway it still seems weird why he does not cache it instead of rereading it each time. Share this post Link to post Share on other sites
ussrlongbow 116 Posted October 14, 2016 As you could see from my second post loading image is not the case. Share this post Link to post Share on other sites
cuel 25 Posted October 14, 2016 I don't get the second code snippet at all. You set index to 1 and then the if will always be true and you only do setCtrlText on 66311. Besides the 1st snippet just clears the text while the 2nd snippet sets the control text to a .paa so yeah I'd expect it to be slower Share this post Link to post Share on other sites
ussrlongbow 116 Posted October 14, 2016 I don't get the second code snippet at all. You set index to 1 and then the if will always be true and you only do setCtrlText on 66311. Besides the 1st snippet just clears the text while the 2nd snippet sets the control text to a .paa so yeah I'd expect it to be slower I passed '1' instead if _this to run in debug console Share this post Link to post Share on other sites
mrcurry 508 Posted October 15, 2016 How many tests did you run for each snippet?Was the result consistent every time?I assume the _index = 1; is just for debug? Disregard, just saw your last post. If the results are consistent over several (read: at least 3) tests there be a mystery, but if you've tried it only once there are a number of possible explanations such as HD delays or simulation FPS drop. Your reworked script is a more elegant solution though. Nice job. 1 Share this post Link to post Share on other sites
ussrlongbow 116 Posted October 15, 2016 How many tests did you run for each snippet? Was the result consistent every time? I assume the _index = 1; is just for debug? Disregard, just saw your last post. If the results are consistent over several (read: at least 3) tests there be a mystery, but if you've tried it only once there are a number of possible explanations such as HD delays or simulation FPS drop. Your reworked script is a more elegant solution though. Nice job. About 10 times (dispersion was less than 1% in each measurement), tried also game and system restart. Same result on stable and profiling branches. Share this post Link to post Share on other sites
killzone_kid 1332 Posted October 15, 2016 For me re-organised code runs 50% slower than combined 1st and 2nd snippet. Also combined speed == 1st speed + 2nd speed taken separately. Share this post Link to post Share on other sites
ussrlongbow 116 Posted October 16, 2016 For me re-organised code runs 50% slower than combined 1st and 2nd snippet. Also combined speed == 1st speed + 2nd speed taken separately. Which build? Share this post Link to post Share on other sites
killzone_kid 1332 Posted October 16, 2016 the latest of course Share this post Link to post Share on other sites
mrcurry 508 Posted October 16, 2016 KK did you define the displays in your tests? Maybe differences there can be the source? Share this post Link to post Share on other sites
killzone_kid 1332 Posted October 16, 2016 KK did you define the displays in your tests? Maybe differences there can be the source? Without exact mission repro this is anyone's guess. Share this post Link to post Share on other sites
ussrlongbow 116 Posted October 16, 2016 Without exact mission repro this is anyone's guess. After re-installing Arma, observing same result, if you are curious - https://www.dropbox.com/s/9qj11uf210jjdw5/adis.VR.zip?dl=0 just open in editor and run code snippets I posted here. Share this post Link to post Share on other sites
killzone_kid 1332 Posted October 16, 2016 After re-installing Arma, observing same result, if you are curious - https://www.dropbox.com/s/9qj11uf210jjdw5/adis.VR.zip?dl=0 just open in editor and run code snippets I posted here. I was able to reproduce the issue. The explanation is simple, pulling texture from a file is a file operation, and those are slow. When you run each of the snippets separately and repeatedly, the texture changes only once. For the rest of 9999 cycles ctrlSetText returns immediately as the texture is the same. When you run them together and measure performance, you change texture every run, twice per the run, hence the massive difference in timing. Anyway, your approach is not optimal, it is better to define pictures for every control in the config and hide them with show = 0; then just hide or show those controls with script: disableSerialization; _index = 1; _display = uiNamespace getVariable "ADIS_MENU_DISPLAY"; (_display displayCtrl 66311) ctrlShow false; (_display displayCtrl 66312) ctrlShow false; (_display displayCtrl 66313) ctrlShow false; (_display displayCtrl 66314) ctrlShow false; (_display displayCtrl 66315) ctrlShow false; (_display displayCtrl 66316) ctrlShow false; (_display displayCtrl 66317) ctrlShow false; (_display displayCtrl 66318) ctrlShow false; if (_index in [1,2,3,4,5,6,7,8]) then { (_display displayCtrl (66310 + _index)) ctrlShow true; rwt_adis_selector_hidden = false; }; There is probably even better way. Share this post Link to post Share on other sites
ussrlongbow 116 Posted October 17, 2016 Thanks, killzone_kid, I'll try with show/hide Share this post Link to post Share on other sites