Skip to content

Commit 7154ed9

Browse files
danpatTheMarex
authored andcommitted
Avoid copying json::Value objects a lot when reallocating vector
1 parent 8f633e6 commit 7154ed9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 5.16.3
2+
- Changes from 5.16.2:
3+
- Performance
4+
- FIXED: Speed up response time when lots of legs exist and geojson is used with `steps=true` [#4936](https://github.com/Project-OSRM/osrm-backend/pull/4936)
5+
16
# 5.16.2
27
- Changes from 5.16.1:
38
- Bugfixes:

include/engine/api/route_api.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,16 @@ class RouteAPI : public BaseAPI
211211
}
212212

213213
std::vector<util::json::Value> step_geometries;
214+
const auto total_step_count =
215+
std::accumulate(legs.begin(), legs.end(), 0, [](const auto &v, const auto &leg) {
216+
return v + leg.steps.size();
217+
});
218+
step_geometries.reserve(total_step_count);
219+
214220
for (const auto idx : util::irange<std::size_t>(0UL, legs.size()))
215221
{
216222
auto &leg_geometry = leg_geometries[idx];
217223

218-
step_geometries.reserve(step_geometries.size() + legs[idx].steps.size());
219-
220224
std::transform(
221225
legs[idx].steps.begin(),
222226
legs[idx].steps.end(),

0 commit comments

Comments
 (0)