-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimise getNetworkDistance in MLD even more #6884
Conversation
0dee408
to
83f34af
Compare
5fa491f
to
4cdfae0
Compare
7701c5f
to
edc4522
Compare
{ | ||
// Shortcuts in forward direction | ||
const auto &cell = | ||
cells.GetCell(metric, level, partition.GetCell(level, heapNode.node)); | ||
auto destination = cell.GetDestinationNodes().begin(); | ||
auto distance = [&cell, node = heapNode.node ]() -> auto | ||
{ | ||
if constexpr (IS_MAP_MATCHING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using new if constexpr
feature from C++17, so it allows to avoid any impact on existing code (if it is not map matching the whole compiler will remove branch and will leave only contents of else
clause).
@@ -281,14 +301,31 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade, | |||
|
|||
const auto level = getNodeQueryLevel(partition, heapNode.node, args...); | |||
|
|||
static constexpr auto IS_MAP_MATCHING = | |||
std::is_same_v<typename SearchEngineData<mld::Algorithm>::MapMatchingQueryHeap, Heap>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added new MapMatchingQueryHeap
to be able to track distance in each heap entry.
} | ||
|
||
for (size_t index = 0; index < unpacked_nodes.size() - 1; ++index) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The essence of optimisation: we are getting rid of this loop, and track distance during routing instead.
@@ -269,10 +270,29 @@ retrievePackedPathFromHeap(const SearchEngineData<Algorithm>::QueryHeap &forward | |||
return packed_path; | |||
} | |||
|
|||
template <bool DIRECTION, typename Algorithm, typename... Args> | |||
template <typename Heap> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main goal here was to make all these algorithms to track distance if they are used in map matching and avoid any overhead in other places: I eventually found a way to do that via using if constexpr
const auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to); | ||
if (!toHeapNode) | ||
|
||
if constexpr (IS_MAP_MATCHING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh all these copy-pasted ifs are a bit ugly, but it seems to be a price for no overhead...
Nice improvement. Well done. 👍🏽 |
Issue
The idea is to calculate distance during routing and get rid of separated loop after routing this way. I left some comments over PR to make it more clear. See
match_mld
benchmark below to see performance improvement.Tasklist
Requirements / Relations
Link any requirements here. Other pull requests this PR is based on?
Benchmark Results
plain u32: 1143.9
aliased double: 1210.16
plain double: 1211.98
plain u32: 1138.74
aliased double: 1212.36
plain double: 1208.4
Stringstream: 11.6403ms
Vector: 7.67532ms
Stringstream: 11.6016ms
Vector: 7.66364ms
4.46997ms/req at 82 coordinate
0.0545118ms/coordinate
Radius 5m:
4.46891ms/req at 82 coordinate
0.054499ms/coordinate
Radius 10m:
15.1349ms/req at 82 coordinate
0.184572ms/coordinate
Radius 15m:
36.815ms/req at 82 coordinate
0.448963ms/coordinate
Radius 30m:
313.327ms/req at 82 coordinate
3.82106ms/coordinate
4.47117ms/req at 82 coordinate
0.0545264ms/coordinate
Radius 5m:
4.4615ms/req at 82 coordinate
0.0544086ms/coordinate
Radius 10m:
15.2068ms/req at 82 coordinate
0.185449ms/coordinate
Radius 15m:
37.1068ms/req at 82 coordinate
0.452521ms/coordinate
Radius 30m:
316.303ms/req at 82 coordinate
3.85735ms/coordinate
3.37703ms/req at 82 coordinate
0.0411833ms/coordinate
Radius 5m:
3.42276ms/req at 82 coordinate
0.041741ms/coordinate
Radius 10m:
12.6636ms/req at 82 coordinate
0.154434ms/coordinate
Radius 15m:
31.4966ms/req at 82 coordinate
0.384105ms/coordinate
Radius 30m:
350.316ms/req at 82 coordinate
4.27215ms/coordinate
2.84541ms/req at 82 coordinate
0.0347001ms/coordinate
Radius 5m:
2.83189ms/req at 82 coordinate
0.0345352ms/coordinate
Radius 10m:
10.3248ms/req at 82 coordinate
0.125912ms/coordinate
Radius 15m:
26.4356ms/req at 82 coordinate
0.322385ms/coordinate
Radius 30m:
301.352ms/req at 82 coordinate
3.67502ms/coordinate
std::vector 11330.3 ms
util::packed_vector 82423.3 ms
slowdown: 7.27459
random read:
std::vector 11209.3 ms
util::packed_vector 33739.8 ms
slowdown: 3.00998
std::vector 11350.7 ms
util::packed_vector 82211 ms
slowdown: 7.24284
random read:
std::vector 11168.9 ms
util::packed_vector 33560.4 ms
slowdown: 3.00481
594.941ms
0.594941ms/req
1000 routes, 2 coordinates, no alternatives, overview=full, steps=true
375.079ms
0.375079ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=full, steps=true
760.43ms
0.76043ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false
152.323ms
0.152323ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false
99.1662ms
0.0991662ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false
134.189ms
0.134189ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false, radius=750
152.045ms
0.152045ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false, radius=750
98.8639ms
0.0988639ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false, radius=750
133.923ms
0.133923ms/req
600.409ms
0.600409ms/req
1000 routes, 2 coordinates, no alternatives, overview=full, steps=true
378.786ms
0.378786ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=full, steps=true
769.029ms
0.769029ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false
161.375ms
0.161375ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false
103.56ms
0.10356ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false
145.516ms
0.145516ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false, radius=750
161.27ms
0.16127ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false, radius=750
104.048ms
0.104048ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false, radius=750
145.495ms
0.145495ms/req
727.614ms
0.727614ms/req
1000 routes, 2 coordinates, no alternatives, overview=full, steps=true
464.97ms
0.46497ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=full, steps=true
947.942ms
0.947942ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false
279.794ms
0.279794ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false
166.12ms
0.16612ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false
298.845ms
0.298845ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false, radius=750
273.348ms
0.273348ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false, radius=750
164.025ms
0.164025ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false, radius=750
295.475ms
0.295475ms/req
729.539ms
0.729539ms/req
1000 routes, 2 coordinates, no alternatives, overview=full, steps=true
471.886ms
0.471886ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=full, steps=true
957.81ms
0.95781ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false
284.501ms
0.284501ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false
168.564ms
0.168564ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false
303.357ms
0.303357ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false, radius=750
277.989ms
0.277989ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false, radius=750
167.514ms
0.167514ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false, radius=750
303.569ms
0.303569ms/req
201.022ms -> 0.0201022 ms/query
10 results:
237.758ms -> 0.0237758 ms/query
206.792ms -> 0.0206792 ms/query
10 results:
237.055ms -> 0.0237055 ms/query