From ad10497503f68db59079d4675cf01732b1ebf2c5 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 28 Apr 2014 18:02:14 -0700 Subject: [PATCH] cache result of parse_expression to speed up map loading - refs #1167 --- benchmark/test_to_bool.cpp | 29 ++++++++++++++++++++++++++- include/mapnik/xml_attribute_cast.hpp | 12 ++++++++++- include/mapnik/xml_tree.hpp | 1 - localize.sh | 9 ++++----- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/benchmark/test_to_bool.cpp b/benchmark/test_to_bool.cpp index 92f073156..62b9d13a0 100644 --- a/benchmark/test_to_bool.cpp +++ b/benchmark/test_to_bool.cpp @@ -26,4 +26,31 @@ public: } }; -BENCHMARK(test,"string->bool") +class test2 : public benchmark::test_case +{ + std::string value_; +public: + test2(mapnik::parameters const& params) + : test_case(params), + value_("1.23456789") {} + bool validate() const + { + double result = 0; + mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result); + if (result != 1.23456789) return false; + result = 0; + mapnik::util::string2double(value_,result); + return (result == 1.23456789); + } + void operator()() const + { + for (std::size_t i=0;ibool") +BENCHMARK(test2,"string->double") diff --git a/include/mapnik/xml_attribute_cast.hpp b/include/mapnik/xml_attribute_cast.hpp index 76562f0c2..d5d527972 100644 --- a/include/mapnik/xml_attribute_cast.hpp +++ b/include/mapnik/xml_attribute_cast.hpp @@ -180,7 +180,17 @@ struct do_xml_attribute_cast { static inline boost::optional xml_attribute_cast_impl(xml_tree const& tree, std::string const& source) { - return parse_expression(source, tree.expr_grammar); + std::map::const_iterator itr = tree.expr_cache_.find(source); + if (itr != tree.expr_cache_.end()) + { + return itr->second; + } + else + { + mapnik::expression_ptr expr = parse_expression(source, tree.expr_grammar); + tree.expr_cache_.insert(std::move(std::make_pair(source,expr))); + return expr; + } } }; diff --git a/include/mapnik/xml_tree.hpp b/include/mapnik/xml_tree.hpp index d44d935f5..77c7034a6 100644 --- a/include/mapnik/xml_tree.hpp +++ b/include/mapnik/xml_tree.hpp @@ -53,7 +53,6 @@ private: std::string file_; transcoder tr_; public: - mutable std::map color_cache_; mutable std::map expr_cache_; mapnik::css_color_grammar color_grammar; mapnik::expression_grammar expr_grammar; diff --git a/localize.sh b/localize.sh index 0f327b384..738d1fc47 100755 --- a/localize.sh +++ b/localize.sh @@ -1,13 +1,12 @@ #!/bin/bash UNAME=$(uname -s) -CURRENT_DIR=$(pwd) - +export CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" if [ ${UNAME} = 'Darwin' ]; then - export DYLD_LIBRARY_PATH="${CURRENT_DIR}/src/":${DYLD_LIBRARY_PATH} + export DYLD_LIBRARY_PATH="${CURRENT_DIR}/src/" else - export LD_LIBRARY_PATH="${CURRENT_DIR}/src/":${DYLD_LIBRARY_PATH} + export LD_LIBRARY_PATH="${CURRENT_DIR}/src/" fi -export PYTHONPATH="${CURRENT_DIR}/bindings/python/":${PYTHONPATH} +export PYTHONPATH="${CURRENT_DIR}/bindings/python/" export MAPNIK_FONT_DIRECTORY="${CURRENT_DIR}/fonts/dejavu-fonts-ttf-2.33/ttf/" export MAPNIK_INPUT_PLUGINS_DIRECTORY="${CURRENT_DIR}/plugins/input/" export PATH="${CURRENT_DIR}/bin/":${PATH}