Skip to content

Commit 9a4b464

Browse files
Improve performance of JSON rendering (#6380)
1 parent 41fd947 commit 9a4b464

18 files changed

+318
-712
lines changed

.github/workflows/osrm-backend.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ jobs:
715715
pushd ${OSRM_BUILD_DIR}
716716
make --jobs=${JOBS} benchmarks
717717
./src/benchmarks/alias-bench
718+
./src/benchmarks/json-render-bench ../src/benchmarks/portugal_to_korea.json
718719
./src/benchmarks/match-bench ../test/data/ch/monaco.osrm
719720
./src/benchmarks/packedvector-bench
720721
./src/benchmarks/rtree-bench ../test/data/monaco.osrm.ramIndex ../test/data/monaco.osrm.fileIndex ../test/data/monaco.osrm.nbg_nodes

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- NodeJS:
1010
- FIXED: Support `skip_waypoints` in Node bindings [#6060](https://github.com/Project-OSRM/osrm-backend/pull/6060)
1111
- Misc:
12+
- CHANGED: Improve performance of JSON rendering. Fix undefined behaviour in JSON numbers formatting. [#6380](https://github.com/Project-OSRM/osrm-backend/pull/6380)
1213
- ADDED: Add timestamps for logs. [#6375](https://github.com/Project-OSRM/osrm-backend/pull/6375)
1314
- CHANGED: Improve performance of map matching via getPathDistance optimization. [#6378](https://github.com/Project-OSRM/osrm-backend/pull/6378)
1415
- CHANGED: Optimize RestrictionParser performance. [#6344](https://github.com/Project-OSRM/osrm-backend/pull/6344)

features/testbot/annotations.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@ Feature: Annotations
115115

116116
When I route I should get
117117
| from | to | route | a:speed | a:distance | a:duration | a:nodes |
118-
| a | c | abc,abc | 10:10 | 249.987619:299.962882 | 25:30 | 1:2:3 |
118+
| a | c | abc,abc | 10:10 | 249.987618946:299.962882039 | 25:30 | 1:2:3 |

features/testbot/matching.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ Feature: Basic Map Matching
809809

810810
# These should have the same weights/duration in either direction
811811
When I match I should get
812-
| trace | geometry | a:distance | a:duration | a:weight | duration |
813-
| 2345 | 1.00018,1,1.000314,1 | 14.914666 | 1.4 | 1.4 | 1.4 |
814-
| 4321 | 1.00027,1,1.000135,1 | 15.02597 | 1.5 | 1.5 | 1.5 |
812+
| trace | geometry | a:distance | a:duration | a:weight | duration |
813+
| 2345 | 1.00018,1,1.000314,1 | 14.914666491 | 1.4 | 1.4 | 1.4 |
814+
| 4321 | 1.00027,1,1.000135,1 | 15.025969972 | 1.5 | 1.5 | 1.5 |
815815

features/testbot/snap_intersection.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ Feature: Snapping at intersections
570570
| a,f,k | ac,cf,cf,fj,kj,kj | 132.8s | 132.8 |
571571
| k,f | ik,fi,fi | 54.3s | 54.3 |
572572
| f,a | ef,ae,ae | 66.6s | 66.6 |
573-
| k,f,a | kj,fj,fj,ef,ae,ae | 141.4s | 141.4 |
573+
| k,f,a | kj,fj,fj,ef,ae,ae | 141.399999999s | 141.399999999 |
574574

575575
When I request a travel time matrix I should get
576576
| | a | f | k |
@@ -626,4 +626,4 @@ Feature: Snapping at intersections
626626
| a,f,k | ad,df,df,fj,kj,kj | 105.6s | 105.6 |
627627
| k,f | ik,fi,fi | 54.3s | 54.3 |
628628
| f,a | ef,ae,ae | 66.6s | 66.6 |
629-
| k,f,a | ik,fi,fi,ef,ae,ae | 120.9s | 120.9 |
629+
| k,f,a | ik,fi,fi,ef,ae,ae | 120.899999999s | 120.899999999 |

features/testbot/weight.feature

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ Feature: Weight tests
5252
| abc |
5353

5454
When I route I should get
55-
| waypoints | route | distances | weights | times | a:distance | a:duration | a:weight | a:speed |
56-
| s,t | abc,abc | 20m,0m | 2,0 | 2s,0s | 20.034627 | 2 | 2 | 10 |
57-
| t,s | abc,abc | 20m,0m | 2,0 | 2s,0s | 20.034627 | 2 | 2 | 10 |
58-
| s,e | abc,abc | 40m,0m | 3.9,0 | 3.9s,0s | 29.940636:10.017313 | 3:0.9 | 3:0.9 | 10:11.1 |
59-
| e,s | abc,abc | 40m,0m | 3.9,0 | 3.9s,0s | 10.017313:29.940636 | 0.9:3 | 0.9:3 | 11.1:10 |
55+
| waypoints | route | distances | weights | times | a:distance | a:duration | a:weight | a:speed |
56+
| s,t | abc,abc | 20m,0m | 2,0 | 2s,0s | 20.034626629 | 2 | 2 | 10 |
57+
| t,s | abc,abc | 20m,0m | 2,0 | 2s,0s | 20.034626629 | 2 | 2 | 10 |
58+
| s,e | abc,abc | 40m,0m | 3.9,0 | 3.9s,0s | 29.940636463:10.017313314 | 3:0.9 | 3:0.9 | 10:11.1 |
59+
| e,s | abc,abc | 40m,0m | 3.9,0 | 3.9s,0s | 10.017313314:29.940636463 | 0.9:3 | 0.9:3 | 11.1:10 |
6060

6161

6262
Scenario: Step weights -- way_function: fail if no weight or weight_per_meter property

fuzz/escape_json.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
#include <iterator>
66
#include <string>
77

8-
using osrm::util::escape_JSON;
8+
using osrm::util::EscapeJSONString;
99

1010
extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, unsigned long size)
1111
{
1212
const std::string in(reinterpret_cast<const char *>(data), size);
1313

14-
const auto escaped = escape_JSON(in);
14+
std::string escaped;
15+
EscapeJSONString(in, escaped);
1516
escape(escaped.data());
1617

1718
return 0;

include/nodejs/json_v8_renderer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ struct V8Renderer
6060

6161
inline void renderToV8(v8::Local<v8::Value> &out, const osrm::json::Object &object)
6262
{
63-
osrm::json::Value value = object;
64-
mapbox::util::apply_visitor(V8Renderer(out), value);
63+
V8Renderer renderer(out);
64+
renderer(object);
6565
}
6666
} // namespace node_osrm
6767

include/util/cast.hpp

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)