Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2018-04-18 15:04:31 +0300
committerTatiana Yan <tatiana.kondakova@gmail.com>2018-04-19 15:16:12 +0300
commitdf3fecf96c54b141bb4eb66d18665d1b2bad70c9 (patch)
tree9aec67a10908202d0cf7791f9e41debb5896c956 /routing
parent50d45e1f91c65c9f3e81c0e095181b16b1abfc13 (diff)
Performance and memory optimization for cross mwm routing.
Diffstat (limited to 'routing')
-rw-r--r--routing/index_graph.cpp6
-rw-r--r--routing/index_graph.hpp3
-rw-r--r--routing/index_graph_loader.cpp42
-rw-r--r--routing/index_graph_loader.hpp1
-rw-r--r--routing/routing_tests/index_graph_tools.hpp1
-rw-r--r--routing/single_vehicle_world_graph.cpp2
6 files changed, 42 insertions, 13 deletions
diff --git a/routing/index_graph.cpp b/routing/index_graph.cpp
index 8cd879231b..6089d4bf94 100644
--- a/routing/index_graph.cpp
+++ b/routing/index_graph.cpp
@@ -80,7 +80,11 @@ void IndexGraph::GetEdgeList(Segment const & segment, bool isOutgoing, vector<Se
}
}
-void IndexGraph::Build(uint32_t numJoints) { m_jointIndex.Build(m_roadIndex, numJoints); }
+void IndexGraph::Build(uint32_t numJoints)
+{
+ m_jointIndex.Build(m_roadIndex, numJoints);
+ m_isBuilt = true;
+}
void IndexGraph::Import(vector<Joint> const & joints)
{
diff --git a/routing/index_graph.hpp b/routing/index_graph.hpp
index a20861de94..4155c5caa6 100644
--- a/routing/index_graph.hpp
+++ b/routing/index_graph.hpp
@@ -65,6 +65,8 @@ public:
m_roadIndex.PushFromSerializer(jointId, rp);
}
+ bool IsBuilt() const { return m_isBuilt; }
+
template <typename F>
void ForEachRoad(F && f) const
{
@@ -95,5 +97,6 @@ private:
JointIndex m_jointIndex;
RestrictionVec m_restrictions;
RoadAccess m_roadAccess;
+ bool m_isBuilt = false;
};
} // namespace routing
diff --git a/routing/index_graph_loader.cpp b/routing/index_graph_loader.cpp
index 42fb13f23c..1563c7270f 100644
--- a/routing/index_graph_loader.cpp
+++ b/routing/index_graph_loader.cpp
@@ -23,11 +23,15 @@ public:
shared_ptr<EdgeEstimator> estimator, Index & index);
// IndexGraphLoader overrides:
- virtual IndexGraph & GetIndexGraph(NumMwmId numMwmId) override;
- virtual void Clear() override;
+ Geometry & GetGeometry(NumMwmId numMwmId) override;
+ IndexGraph & GetIndexGraph(NumMwmId numMwmId) override;
+ void Clear() override;
private:
- IndexGraph & Load(NumMwmId mwmId);
+ /// \brief Constructs IndexGraph without deserializing data and building IndexGraph.
+ IndexGraph & Init(NumMwmId mwmId);
+ /// \brief Deserializes data and builds IndexGraph.
+ IndexGraph & Deserialize(NumMwmId numMwmId, IndexGraph & graph);
VehicleType m_vehicleType;
bool m_loadAltitudes;
@@ -54,16 +58,25 @@ IndexGraphLoaderImpl::IndexGraphLoaderImpl(
CHECK(m_estimator, ());
}
+Geometry & IndexGraphLoaderImpl::GetGeometry(NumMwmId numMwmId)
+{
+ auto it = m_graphs.find(numMwmId);
+ if (it != m_graphs.end())
+ return it->second->GetGeometry();
+
+ return Init(numMwmId).GetGeometry();
+}
+
IndexGraph & IndexGraphLoaderImpl::GetIndexGraph(NumMwmId numMwmId)
{
auto it = m_graphs.find(numMwmId);
if (it != m_graphs.end())
- return *it->second;
+ return it->second->IsBuilt() ? *it->second : Deserialize(numMwmId, *it->second);
- return Load(numMwmId);
+ return Deserialize(numMwmId, Init(numMwmId));
}
-IndexGraph & IndexGraphLoaderImpl::Load(NumMwmId numMwmId)
+IndexGraph & IndexGraphLoaderImpl::Init(NumMwmId numMwmId)
{
platform::CountryFile const & file = m_numMwmIds->GetFile(numMwmId);
MwmSet::MwmHandle handle = m_index.GetMwmHandleByCountryFile(file);
@@ -73,15 +86,22 @@ IndexGraph & IndexGraphLoaderImpl::Load(NumMwmId numMwmId)
shared_ptr<VehicleModelInterface> vehicleModel =
m_vehicleModelFactory->GetVehicleModelForCountry(file.GetName());
- auto graphPtr = make_unique<IndexGraph>(
- GeometryLoader::Create(m_index, handle, vehicleModel, m_loadAltitudes),
- m_estimator);
- IndexGraph & graph = *graphPtr;
+ return *(
+ m_graphs[numMwmId] = make_unique<IndexGraph>(
+ GeometryLoader::Create(m_index, handle, vehicleModel, m_loadAltitudes), m_estimator));
+}
+
+IndexGraph & IndexGraphLoaderImpl::Deserialize(NumMwmId numMwmId, IndexGraph & graph)
+{
+ CHECK(!graph.IsBuilt(), ());
+ platform::CountryFile const & file = m_numMwmIds->GetFile(numMwmId);
+ MwmSet::MwmHandle handle = m_index.GetMwmHandleByCountryFile(file);
+ if (!handle.IsAlive())
+ MYTHROW(RoutingException, ("Can't get mwm handle for", file));
my::Timer timer;
MwmValue const & mwmValue = *handle.GetValue<MwmValue>();
DeserializeIndexGraph(mwmValue, m_vehicleType, graph);
- m_graphs[numMwmId] = move(graphPtr);
LOG(LINFO, (ROUTING_FILE_TAG, "section for", file.GetName(), "loaded in", timer.ElapsedSeconds(),
"seconds"));
return graph;
diff --git a/routing/index_graph_loader.hpp b/routing/index_graph_loader.hpp
index 768cf09476..63d698ed89 100644
--- a/routing/index_graph_loader.hpp
+++ b/routing/index_graph_loader.hpp
@@ -18,6 +18,7 @@ class IndexGraphLoader
public:
virtual ~IndexGraphLoader() = default;
+ virtual Geometry & GetGeometry(NumMwmId numMwmId) = 0;
virtual IndexGraph & GetIndexGraph(NumMwmId mwmId) = 0;
virtual void Clear() = 0;
diff --git a/routing/routing_tests/index_graph_tools.hpp b/routing/routing_tests/index_graph_tools.hpp
index 671948d73c..1ca3886a76 100644
--- a/routing/routing_tests/index_graph_tools.hpp
+++ b/routing/routing_tests/index_graph_tools.hpp
@@ -88,6 +88,7 @@ public:
// IndexGraphLoader overrides:
~TestIndexGraphLoader() override = default;
+ Geometry & GetGeometry(NumMwmId mwmId) override { return GetIndexGraph(mwmId).GetGeometry(); }
IndexGraph & GetIndexGraph(NumMwmId mwmId) override;
void Clear() override;
diff --git a/routing/single_vehicle_world_graph.cpp b/routing/single_vehicle_world_graph.cpp
index 60b7a027d8..47552df7ac 100644
--- a/routing/single_vehicle_world_graph.cpp
+++ b/routing/single_vehicle_world_graph.cpp
@@ -116,7 +116,7 @@ unique_ptr<TransitInfo> SingleVehicleWorldGraph::GetTransitInfo(Segment const &)
RoadGeometry const & SingleVehicleWorldGraph::GetRoadGeometry(NumMwmId mwmId, uint32_t featureId)
{
- return m_loader->GetIndexGraph(mwmId).GetGeometry().GetRoad(featureId);
+ return m_loader->GetGeometry(mwmId).GetRoad(featureId);
}
void SingleVehicleWorldGraph::GetTwinsInner(Segment const & segment, bool isOutgoing,