diff --git a/CHANGELOG.md b/CHANGELOG.md index c9a1d3ccd..a69ee5abd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Features - 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 - 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 + - Speed up pre-processing by only running the Lua `node_function` for nodes that have tags. Cuts OSM file parsing time in half. - Files - .osrm.nodes file was renamed to .nbg_nodes and .ebg_nodes was added - Guidance diff --git a/include/extractor/profile_properties.hpp b/include/extractor/profile_properties.hpp index 43871c53e..ceb513e09 100644 --- a/include/extractor/profile_properties.hpp +++ b/include/extractor/profile_properties.hpp @@ -22,7 +22,7 @@ struct ProfileProperties : traffic_signal_penalty(0), u_turn_penalty(0), max_speed_for_map_matching(DEFAULT_MAX_SPEED), continue_straight_at_waypoint(true), use_turn_restrictions(false), left_hand_driving(false), fallback_to_duration(true), - weight_name{"duration"} + weight_name{"duration"}, call_tagless_node_function(true) { BOOST_ASSERT(weight_name[MAX_WEIGHT_NAME_LENGTH] == '\0'); } @@ -88,6 +88,8 @@ struct ProfileProperties char weight_name[MAX_WEIGHT_NAME_LENGTH + 1]; unsigned weight_precision = 1; bool force_split_edges = false; + + bool call_tagless_node_function = true; }; } } diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index 8925a7664..3d0aba6df 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -15,6 +15,11 @@ properties.continue_straight_at_waypoint = false properties.weight_name = 'duration' --properties.weight_name = 'cyclability' +-- Set to true if you need to call the node_function for every node. +-- Generally can be left as false to avoid unnecessary Lua calls +-- (which slow down pre-processing). +properties.call_tagless_node_function = false + local default_speed = 15 local walking_speed = 6 diff --git a/profiles/car.lua b/profiles/car.lua index f37562c3a..2810a1a13 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -20,6 +20,12 @@ properties.weight_name = 'routability' -- For shortest distance without penalties for accessibility --properties.weight_name = 'distance' +-- Set to true if you need to call the node_function for every node. +-- Generally can be left as false to avoid unnecessary Lua calls +-- (which slow down pre-processing). +properties.call_tagless_node_function = false + + local profile = { default_mode = mode.driving, default_speed = 10, diff --git a/profiles/foot.lua b/profiles/foot.lua index 98cd5e199..1749b23b7 100644 --- a/profiles/foot.lua +++ b/profiles/foot.lua @@ -14,6 +14,11 @@ properties.continue_straight_at_waypoint = false properties.weight_name = 'duration' --properties.weight_name = 'routability' +-- Set to true if you need to call the node_function for every node. +-- Generally can be left as false to avoid unnecessary Lua calls +-- (which slow down pre-processing). +properties.call_tagless_node_function = false + local walking_speed = 5 local profile = { diff --git a/profiles/rasterbot.lua b/profiles/rasterbot.lua index bf8c2369e..2c2a02f21 100644 --- a/profiles/rasterbot.lua +++ b/profiles/rasterbot.lua @@ -3,6 +3,11 @@ api_version = 1 properties.force_split_edges = true +-- Set to true if you need to call the node_function for every node. +-- Generally can be left as false to avoid unnecessary Lua calls +-- (which slow down pre-processing). +properties.call_tagless_node_function = false + -- Minimalist node_ and way_functions in order to test source_ and segment_functions function node_function (node, result) diff --git a/profiles/rasterbotinterp.lua b/profiles/rasterbotinterp.lua index e3dcbb74d..bcc4f11b5 100644 --- a/profiles/rasterbotinterp.lua +++ b/profiles/rasterbotinterp.lua @@ -1,6 +1,11 @@ api_version = 1 -- Rasterbot profile +-- Set to true if you need to call the node_function for every node. +-- Generally can be left as false to avoid unnecessary Lua calls +-- (which slow down pre-processing). +properties.call_tagless_node_function = false + -- Minimalist node_ and way_functions in order to test source_ and segment_functions function node_function (node, result) diff --git a/profiles/testbot.lua b/profiles/testbot.lua index 9321ffc0e..1461845ed 100644 --- a/profiles/testbot.lua +++ b/profiles/testbot.lua @@ -22,6 +22,11 @@ properties.use_turn_restrictions = true properties.max_speed_for_map_matching = 30/3.6 --km -> m/s properties.weight_name = 'duration' +-- Set to true if you need to call the node_function for every node. +-- Generally can be left as false to avoid unnecessary Lua calls +-- (which slow down pre-processing). +properties.call_tagless_node_function = false + local uturn_penalty = 20 local traffic_light_penalty = 7 -- seconds diff --git a/src/extractor/scripting_environment_lua.cpp b/src/extractor/scripting_environment_lua.cpp index df2fff278..4755b3b08 100644 --- a/src/extractor/scripting_environment_lua.cpp +++ b/src/extractor/scripting_environment_lua.cpp @@ -249,7 +249,9 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) "max_turn_weight", sol::property(&ProfileProperties::GetMaxTurnWeight), "force_split_edges", - &ProfileProperties::force_split_edges); + &ProfileProperties::force_split_edges, + "call_tagless_node_function", + &ProfileProperties::call_tagless_node_function); context.state.new_usertype>( "vector", @@ -510,7 +512,9 @@ void Sol2ScriptingEnvironment::ProcessElements( { case osmium::item_type::node: result_node.clear(); - if (local_context.has_node_function) + if (local_context.has_node_function && + (!static_cast(*entity).tags().empty() || + local_context.properties.call_tagless_node_function)) { local_context.ProcessNode(static_cast(*entity), result_node);