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

@@ -109,7 +109,12 @@ namespace BlackCore
void ISimulator::rememberElevationAndCG(const CCallsign &callsign, const Geo::CElevationPlane &elevation, const CLength &cg)
{
if (callsign.isEmpty()) { return; }
if (!elevation.isNull()) { this->rememberGroundElevation(elevation); }
if (!elevation.isNull())
{
const int aircraftCount = this->getAircraftInRangeCount();
this->setRememberMaxElevations(aircraftCount * 3); // at least 3 elevations per aircraft, even better as not all are requesting elevations
this->rememberGroundElevation(elevation);
}
if (!cg.isNull() && !this->hasSameCG(cg, callsign)) { this->insertCG(cg, callsign); }
}
@@ -120,9 +125,11 @@ namespace BlackCore
{
// decouple, follow up of signal can include unloading
// simulator so this should happen strictly asyncronously (which is like forcing Qt::QueuedConnection)
QPointer<ISimulator> myself(this);
QTimer::singleShot(0, this, [ = ]
{
emit this->simulatorStatusChanged(newStatus);
if (!myself) { return; }
emit myself->simulatorStatusChanged(newStatus);
});
}
}

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)
{ }

View File

@@ -33,7 +33,6 @@ namespace BlackMisc
{
public:
//! All remembered coordiantes
//! \remark might be a relatively large list
//! \threadsafe
Geo::CCoordinateGeodeticList getElevationCoordinates() const;
@@ -77,10 +76,22 @@ namespace BlackMisc
//! \threadsafe
bool hasSameCG(const PhysicalQuantities::CLength &cg, const Aviation::CCallsign &callsign) const;
//! Set number of elevations kept
//! \threadsafe
int setRememberMaxElevations(int max);
//! Get number of max. number of elevations
//! \threadsafe
int getRememberMaxElevations() const;
protected:
//! Ctor
ISimulationEnvironmentProvider(const CSimulatorPluginInfo &pluginInfo);
//! All remembered coordiantes plus max remembered situations
//! \threadsafe
Geo::CCoordinateGeodeticList getElevationCoordinates(int &maxRemembered) const;
//! New plugin info and default model
//! \remark normally only used by emulated driver
//! \threadsafe
@@ -107,7 +118,7 @@ namespace BlackMisc
//! Only keep closest ones
//! \threadsafe
int cleanUpElevations(const Geo::ICoordinateGeodetic &referenceCoordinate, int maxNumber = MaxElevations);
int cleanUpElevations(const Geo::ICoordinateGeodetic &referenceCoordinate, int maxNumber = -1);
//! Remember a given elevation
//! \threadsafe
@@ -129,9 +140,8 @@ namespace BlackMisc
//! Min.range considered as single point
static PhysicalQuantities::CLength minRange(const PhysicalQuantities::CLength &range);
static constexpr int MaxElevations = 1000; //!< How many elevations we keep
private:
int m_maxElevations = 100; //!< How many elevations we keep
CAircraftModel m_defaultModel; //!< default model
CSimulatorPluginInfo m_simulatorPluginInfo; //!< info object
Geo::CCoordinateGeodeticList m_elvCoordinates;