Skip to content
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

Speed up generation of step geometries when there are lots of legs #4936

Merged
merged 1 commit into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- CHANGED #4845: Updated segregated intersection identification
- Documentation:
- ADDED: Add documentation about OSM node ids in nearest service response [#4436](https://github.com/Project-OSRM/osrm-backend/pull/4436)
- Performance
- 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.0
Expand Down
8 changes: 6 additions & 2 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,16 @@ class RouteAPI : public BaseAPI
}

std::vector<util::json::Value> step_geometries;
const auto total_step_count =
std::accumulate(legs.begin(), legs.end(), 0, [](const auto &v, const auto &leg) {
return v + leg.steps.size();
});
step_geometries.reserve(total_step_count);

for (const auto idx : util::irange<std::size_t>(0UL, legs.size()))
{
auto &leg_geometry = leg_geometries[idx];

step_geometries.reserve(step_geometries.size() + legs[idx].steps.size());

std::transform(
legs[idx].steps.begin(),
legs[idx].steps.end(),
Expand Down