Optimize calls to SGPropertyNode::getNode in FGAtmosphere::Calculate#1382
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1382 +/- ##
==========================================
+ Coverage 25.24% 25.29% +0.05%
==========================================
Files 169 169
Lines 18549 18563 +14
==========================================
+ Hits 4682 4696 +14
Misses 13867 13867 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ade9a23 to
85eb24d
Compare
|
Just for the sake of comparing time execution, on my (quite old) PC the script |
I was wondering about the necessity of |
|
Indeed I have made this PR targeting 100% backward compatibility without questioning whether or not that would make sense. That's a good point you are making: do we really need to check on every iteration if the property has been created ? One option could be to check when |
|
Yep, I wasn't aware of this atmosphere override option, so wasn't really sure if there was a standard for when the override property needed to be created etc. So yes, safest option for now in terms of backwards compatibility is to go with your current implementation. A 3%-4% increase is still a pretty useful improvement. |
Neither was I. I have discovered or, should I say, paid attention to it when investigating issue #1375
OK. The PR has been merged. |

The problem
As I mentioned in #1375 (comment), the method
FGAtmosphere::Calculateis spending a significant amount of time resolving property names into property nodes (i.e. callingSGPropertyNode::getNode):Actually the logic is based on the existence of the nodes
atmosphere/override/temperature,atmosphere/override/pressureandatmosphere/override/density.jsbsim/src/models/FGAtmosphere.cpp
Lines 142 to 170 in 5988bb4
If one of these nodes is existing then the temperature/pressure/density is extracted from its corresponding node. This feature is designed to use an external atmospheric model that would provide its data through the
atmosphere/overrideproperties.The problem is that interrogating
SGPropertyNode::getNodeat each iteration is costly: 72012 calls toSGPropertyNode::getNodetranslates into 3,940,012 calls tostrncmp(in the screenshot above it is an SSE2 optimized version of it).The proposed solution
Since all the nodes are located below
atmosphere/overridethen the new code is only testing ifatmosphere/overrideis existing at each iteration. If it does not exist then there is no point in interrogating the other nodes for the temperature/pressure/density. This is dividing the number of calls toSGPropertyNode::getNodeby 3 and the time spent inFGAtmosphere::Calculateby roughly the same order of magnitude.In addition to that, once the existence of a node is confirmed, it is registered in a variable of type
SGPropertyNode_ptrso thatFGAtmosphere::Calculatewill no longer need to resolve the name into a node thus avoiding further calls toSGPropertyNode::getNode.