Skip to content

Commit cd8fb82

Browse files
danpatPatrick Niklaus
authored andcommitted
Add flag to allow skipping calling node function for nodes with no tags.
1 parent 5c8e2b6 commit cd8fb82

File tree

9 files changed

+41
-3
lines changed

9 files changed

+41
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Features
1313
- Added conditional restriction support with `parse-conditional-restrictions=true|false` to osrm-extract. This option saves conditional turn restrictions to the .restrictions file for parsing by contract later. Added `parse-conditionals-from-now=utc time stamp` and `--time-zone-file=/path/to/file` to osrm-contract
1414
- Command-line tools (osrm-extract, osrm-contract, osrm-routed, etc) now return error codes and legible error messages for common problem scenarios, rather than ugly C++ crashes
15+
- Speed up pre-processing by only running the Lua `node_function` for nodes that have tags. Cuts OSM file parsing time in half.
1516
- Files
1617
- .osrm.nodes file was renamed to .nbg_nodes and .ebg_nodes was added
1718
- Guidance

include/extractor/profile_properties.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct ProfileProperties
2222
: traffic_signal_penalty(0), u_turn_penalty(0),
2323
max_speed_for_map_matching(DEFAULT_MAX_SPEED), continue_straight_at_waypoint(true),
2424
use_turn_restrictions(false), left_hand_driving(false), fallback_to_duration(true),
25-
weight_name{"duration"}
25+
weight_name{"duration"}, call_tagless_node_function(true)
2626
{
2727
BOOST_ASSERT(weight_name[MAX_WEIGHT_NAME_LENGTH] == '\0');
2828
}
@@ -88,6 +88,8 @@ struct ProfileProperties
8888
char weight_name[MAX_WEIGHT_NAME_LENGTH + 1];
8989
unsigned weight_precision = 1;
9090
bool force_split_edges = false;
91+
92+
bool call_tagless_node_function = true;
9193
};
9294
}
9395
}

profiles/bicycle.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ properties.continue_straight_at_waypoint = false
1515
properties.weight_name = 'duration'
1616
--properties.weight_name = 'cyclability'
1717

18+
-- Set to true if you need to call the node_function for every node.
19+
-- Generally can be left as false to avoid unnecessary Lua calls
20+
-- (which slow down pre-processing).
21+
properties.call_tagless_node_function = false
22+
1823

1924
local default_speed = 15
2025
local walking_speed = 6

profiles/car.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ properties.weight_name = 'routability'
2020
-- For shortest distance without penalties for accessibility
2121
--properties.weight_name = 'distance'
2222

23+
-- Set to true if you need to call the node_function for every node.
24+
-- Generally can be left as false to avoid unnecessary Lua calls
25+
-- (which slow down pre-processing).
26+
properties.call_tagless_node_function = false
27+
28+
2329
local profile = {
2430
default_mode = mode.driving,
2531
default_speed = 10,

profiles/foot.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ properties.continue_straight_at_waypoint = false
1414
properties.weight_name = 'duration'
1515
--properties.weight_name = 'routability'
1616

17+
-- Set to true if you need to call the node_function for every node.
18+
-- Generally can be left as false to avoid unnecessary Lua calls
19+
-- (which slow down pre-processing).
20+
properties.call_tagless_node_function = false
21+
1722
local walking_speed = 5
1823

1924
local profile = {

profiles/rasterbot.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ api_version = 1
33

44
properties.force_split_edges = true
55

6+
-- Set to true if you need to call the node_function for every node.
7+
-- Generally can be left as false to avoid unnecessary Lua calls
8+
-- (which slow down pre-processing).
9+
properties.call_tagless_node_function = false
10+
611
-- Minimalist node_ and way_functions in order to test source_ and segment_functions
712

813
function node_function (node, result)

profiles/rasterbotinterp.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
api_version = 1
22
-- Rasterbot profile
33

4+
-- Set to true if you need to call the node_function for every node.
5+
-- Generally can be left as false to avoid unnecessary Lua calls
6+
-- (which slow down pre-processing).
7+
properties.call_tagless_node_function = false
8+
49
-- Minimalist node_ and way_functions in order to test source_ and segment_functions
510

611
function node_function (node, result)

profiles/testbot.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ properties.use_turn_restrictions = true
2222
properties.max_speed_for_map_matching = 30/3.6 --km -> m/s
2323
properties.weight_name = 'duration'
2424

25+
-- Set to true if you need to call the node_function for every node.
26+
-- Generally can be left as false to avoid unnecessary Lua calls
27+
-- (which slow down pre-processing).
28+
properties.call_tagless_node_function = false
29+
2530
local uturn_penalty = 20
2631
local traffic_light_penalty = 7 -- seconds
2732

src/extractor/scripting_environment_lua.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
249249
"max_turn_weight",
250250
sol::property(&ProfileProperties::GetMaxTurnWeight),
251251
"force_split_edges",
252-
&ProfileProperties::force_split_edges);
252+
&ProfileProperties::force_split_edges,
253+
"call_tagless_node_function",
254+
&ProfileProperties::call_tagless_node_function);
253255

254256
context.state.new_usertype<std::vector<std::string>>(
255257
"vector",
@@ -510,7 +512,9 @@ void Sol2ScriptingEnvironment::ProcessElements(
510512
{
511513
case osmium::item_type::node:
512514
result_node.clear();
513-
if (local_context.has_node_function)
515+
if (local_context.has_node_function &&
516+
(!static_cast<const osmium::Node &>(*entity).tags().empty() ||
517+
local_context.properties.call_tagless_node_function))
514518
{
515519
local_context.ProcessNode(static_cast<const osmium::Node &>(*entity),
516520
result_node);

0 commit comments

Comments
 (0)