First thing is to create a simple standalone example that shows the problem as listeners should work fine for strings, unless the underlying property is tied (i.e. the property is backed by a C++ variable). However even tied properties can support listeners - it just needs some extra C++ and so a standalone example is essential in tracking down what is actually going on.
Generally I'd expect the performance hit from a 10hz providing that the amount of work is minimised; i.e. to simulate a listener
something like;
- Code: Select all
var lastV = "----"; # set to something to ensure called the first time
var currentV = "";
var propV = props.globals.getNode("/some/property");
check_for_updates(){
currentV = propV.getValue();
if (currentV != lastV){
lastV = currentV;
update_method(currentV);
}
}
udploop = maketimer(1/refresh, nil, check_for_updates);
udploop.start();
looking at the lines
https://github.com/hbeni/fgcom-mumble/b ... 72C4-L80C6 this is doing more work than it should; firstly it should only do things when values change (see above), but also should not use expensive operations.
- Code: Select all
72 var update_udp_output = func() {
73 FGComMumble_radios.update_radios();
74 var out_prop = props.globals.getNode(mySettingsRootPath ~ "/output/udp",1);
75 var str_v = [];
76 foreach (r_out; FGComMumble_radios.GenericRadio.outputRootNode.getChildren("COM")) {
77 append(str_v, r_out.getValue());
78 }
79 out_prop.setValue(string.join(",", str_v));
80 }
Line 73: not sure how expensive this method is
Line 74: ideally this would be called outside of the loop as a getNode is a costly/slow operation.
Line 75: move this to a module level variable to reduce GC
Line 76: if this is mostly static it would benefit from being in a cached array (as getChildren is a costly/slow operation)
Generally it is better to have a few uS every second rather than big work every 10 seconds; so in that sense a 10hz timer is right; although if the value is only likely to change once in a while then maybe a 5 second timer would be more appropriate.
With addons I think it is important to make the code as efficient as possible as obivously each addon will increase the load slightly.