Project-OSRM / osrm-backend

Open Source Routing Machine - C++ backend
http://map.project-osrm.org
BSD 2-Clause "Simplified" License
6.42k stars 3.4k forks source link

Use custom struct instead of std::pair in QueryHeap #6921

Closed SiarheiFedartsou closed 5 months ago

SiarheiFedartsou commented 5 months ago

Benchmark Results

Benchmark Base PR
alias aliased u32: 1087.89
plain u32: 1085.74
aliased double: 957.784
plain double: 954.912
aliased u32: 1094.16
plain u32: 1143.48
aliased double: 1181.03
plain double: 1173.1
json-render String: 6.5949ms
Stringstream: 9.33359ms
Vector: 6.8915ms
String: 6.56282ms
Stringstream: 9.17836ms
Vector: 6.80801ms
match_ch Default radius:
4.46775ms/req at 82 coordinate
0.0544847ms/coordinate
Radius 5m:
4.4405ms/req at 82 coordinate
0.0541524ms/coordinate
Radius 10m:
15.1805ms/req at 82 coordinate
0.185128ms/coordinate
Radius 15m:
37.1138ms/req at 82 coordinate
0.452607ms/coordinate
Radius 30m:
317.423ms/req at 82 coordinate
3.87101ms/coordinate
Default radius:
4.42469ms/req at 82 coordinate
0.0539597ms/coordinate
Radius 5m:
4.38681ms/req at 82 coordinate
0.0534976ms/coordinate
Radius 10m:
15.0091ms/req at 82 coordinate
0.183038ms/coordinate
Radius 15m:
36.6437ms/req at 82 coordinate
0.446875ms/coordinate
Radius 30m:
312.646ms/req at 82 coordinate
3.81276ms/coordinate
match_mld Default radius:
3.34427ms/req at 82 coordinate
0.0407838ms/coordinate
Radius 5m:
2.79952ms/req at 82 coordinate
0.0341405ms/coordinate
Radius 10m:
10.3098ms/req at 82 coordinate
0.125729ms/coordinate
Radius 15m:
26.4945ms/req at 82 coordinate
0.323104ms/coordinate
Radius 30m:
310.665ms/req at 82 coordinate
3.7886ms/coordinate
Default radius:
2.78484ms/req at 82 coordinate
0.0339614ms/coordinate
Radius 5m:
2.7996ms/req at 82 coordinate
0.0341415ms/coordinate
Radius 10m:
10.1723ms/req at 82 coordinate
0.124052ms/coordinate
Radius 15m:
26.0148ms/req at 82 coordinate
0.317254ms/coordinate
Radius 30m:
304.017ms/req at 82 coordinate
3.70753ms/coordinate
packedvector random write:
std::vector 9858.82 ms
util::packed_vector 82186.3 ms
slowdown: 8.33632
random read:
std::vector 8513.61 ms
util::packed_vector 33472.8 ms
slowdown: 3.93168
random write:
std::vector 11236.2 ms
util::packed_vector 73886.6 ms
slowdown: 6.57575
random read:
std::vector 11103.5 ms
util::packed_vector 30234 ms
slowdown: 2.72293
route_ch 1000 routes, 3 coordinates, no alternatives, overview=full, steps=true
509.659ms
0.509659ms/req
1000 routes, 2 coordinates, no alternatives, overview=full, steps=true
351.646ms
0.351646ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=full, steps=true
628.2ms
0.6282ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false
152.53ms
0.15253ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false
97.4741ms
0.0974741ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false
132.57ms
0.13257ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false, radius=750
151.428ms
0.151428ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false, radius=750
97.0949ms
0.0970949ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false, radius=750
132.039ms
0.132039ms/req
1000 routes, 3 coordinates, no alternatives, overview=full, steps=true
511.645ms
0.511645ms/req
1000 routes, 2 coordinates, no alternatives, overview=full, steps=true
353.033ms
0.353033ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=full, steps=true
630.633ms
0.630633ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false
149.976ms
0.149976ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false
96.5049ms
0.0965049ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false
132.923ms
0.132923ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false, radius=750
149.583ms
0.149583ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false, radius=750
96.4442ms
0.0964442ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false, radius=750
131.794ms
0.131794ms/req
route_mld 1000 routes, 3 coordinates, no alternatives, overview=full, steps=true
643.621ms
0.643621ms/req
1000 routes, 2 coordinates, no alternatives, overview=full, steps=true
441.984ms
0.441984ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=full, steps=true
818.912ms
0.818912ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false
280.732ms
0.280732ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false
164.269ms
0.164269ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false
300.394ms
0.300394ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false, radius=750
272.22ms
0.27222ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false, radius=750
161.836ms
0.161836ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false, radius=750
293.598ms
0.293598ms/req
1000 routes, 3 coordinates, no alternatives, overview=full, steps=true
640.204ms
0.640204ms/req
1000 routes, 2 coordinates, no alternatives, overview=full, steps=true
436.477ms
0.436477ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=full, steps=true
815.515ms
0.815515ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false
268.377ms
0.268377ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false
159.875ms
0.159875ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false
287.392ms
0.287392ms/req
1000 routes, 3 coordinates, no alternatives, overview=false, steps=false, radius=750
261.197ms
0.261197ms/req
1000 routes, 2 coordinates, no alternatives, overview=false, steps=false, radius=750
161.217ms
0.161217ms/req
1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false, radius=750
287.302ms
0.287302ms/req
rtree 1 result:
207.75ms -> 0.020775 ms/query
10 results:
243.355ms -> 0.0243355 ms/query
1 result:
207.172ms -> 0.0207172 ms/query
10 results:
243.418ms -> 0.0243418 ms/query
DennisOSRM commented 5 months ago

Nice readability improvement

SiarheiFedartsou commented 5 months ago

Nice readability improvement

I hope it is not only readability :) locally I have slight performance improvement on some of benchmarks. It can be confusing, but there are indeed some reasons why std::pair can be slower than raw struct: https://danlark.org/2020/04/13/why-is-stdpair-broken/ https://www.reddit.com/r/cpp/comments/ar4ghs/stdpair_disappointing_performance/

But tbh I am not 100% sure yet it is the case here.

SiarheiFedartsou commented 5 months ago

e indeed some reasons why std::pair can be slower than raw struct: https://danlark.org/2020/04/13/why-is-stdpair-broken/ https://www.reddit.com/r/cpp/comments/ar4ghs/stdpair_disappointing_performance/

But tbh I am not 100% sure yet it is the case here.

Well, according to our CI benchmark it seems to be indeed a microoptimisation, but hard to say for sure as improvement is really small. Also weird that I see it only for MLD(UPDATE: after re-run there is slight improvement on CH as well, but it is hard to say if it is statistically significant). But as this is nice as readability only thing I propose to merge it anyway.