Ref T270, performance improvement by keeping less elevations cached

Rational: the idea was to keep track of ground elevations of all aircraft and hence using them for other aircraft on ground. But the "hit" ratio is bad, so we only keep a small number of elevations ("the last ones") and use those. The size of the cache is dynamically adjusted. Not moving aircraft are still found in that much smaller list.
This commit is contained in:
Klaus Basan
2018-06-01 01:26:28 +02:00
parent 87b96f8910
commit 2b9d9027a0
3 changed files with 48 additions and 8 deletions

View File

@@ -20,6 +20,7 @@ namespace BlackMisc
bool ISimulationEnvironmentProvider::rememberGroundElevation(const ICoordinateGeodetic &elevationCoordinate, const CLength &epsilon)
{
{
// no 2nd elevation nearby
QReadLocker l(&m_lockElvCoordinates);
if (m_elvCoordinates.containsObjectInRange(elevationCoordinate, minRange(epsilon))) { return false; }
}
@@ -28,7 +29,7 @@ namespace BlackMisc
// * we assume we find them faster
// * and need the more frequently (the recent ones)
QWriteLocker l(&m_lockElvCoordinates);
if (m_elvCoordinates.size() > MaxElevations) { m_elvCoordinates.pop_back(); }
if (m_elvCoordinates.size() > m_maxElevations) { m_elvCoordinates.pop_back(); }
m_elvCoordinates.push_front(elevationCoordinate);
}
return true;
@@ -76,9 +77,18 @@ namespace BlackMisc
return m_elvCoordinates;
}
CCoordinateGeodeticList ISimulationEnvironmentProvider::getElevationCoordinates(int &maxRemembered) const
{
QReadLocker l(&m_lockElvCoordinates);
maxRemembered = m_maxElevations;
return m_elvCoordinates;
}
int ISimulationEnvironmentProvider::cleanUpElevations(const ICoordinateGeodetic &referenceCoordinate, int maxNumber)
{
CCoordinateGeodeticList coordinates(this->getElevationCoordinates());
int currentMax;
CCoordinateGeodeticList coordinates(this->getElevationCoordinates(currentMax));
if (maxNumber < 0) { maxNumber = currentMax; }
const int size = coordinates.size();
if (size <= maxNumber) { return 0; }
coordinates.sortByEuclideanDistanceSquared(referenceCoordinate);
@@ -168,6 +178,19 @@ namespace BlackMisc
return m_cgs[callsign] == cg;
}
int ISimulationEnvironmentProvider::setRememberMaxElevations(int max)
{
QWriteLocker l(&m_lockElvCoordinates);
m_maxElevations = qMax(max, 50);
return m_maxElevations;
}
int ISimulationEnvironmentProvider::getRememberMaxElevations() const
{
QReadLocker l(&m_lockElvCoordinates);
return m_maxElevations;
}
ISimulationEnvironmentProvider::ISimulationEnvironmentProvider(const CSimulatorPluginInfo &pluginInfo) : m_simulatorPluginInfo(pluginInfo)
{ }