From e3064b952029a4fe8f7b65442d23e1112f26bb5f Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 14 Nov 2009 03:45:18 -0500 Subject: Spot optimization for simple automated xact exprs This reduces parsing time in the optimized build by 25%, and was a safe, easy patch. If the "quick predicate evaluator" fails, we disable it from that point on go back to what the standard code does. --- src/xact.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/xact.h') diff --git a/src/xact.h b/src/xact.h index fe748fcc..07f9a6c7 100644 --- a/src/xact.h +++ b/src/xact.h @@ -146,16 +146,18 @@ class auto_xact_t : public xact_base_t { public: predicate_t predicate; + bool try_quick_match; - auto_xact_t() { + auto_xact_t() : try_quick_match(true) { TRACE_CTOR(auto_xact_t, ""); } auto_xact_t(const auto_xact_t& other) - : xact_base_t(), predicate(other.predicate) { + : xact_base_t(), predicate(other.predicate), + try_quick_match(other.try_quick_match) { TRACE_CTOR(auto_xact_t, "copy"); } auto_xact_t(const predicate_t& _predicate) - : predicate(_predicate) + : predicate(_predicate), try_quick_match(true) { TRACE_CTOR(auto_xact_t, "const predicate_t&"); } -- cgit v1.2.3 From d89c60f49cf1eb2df3cc761b9790e6fc47cc7c96 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 14 Nov 2009 04:29:53 -0500 Subject: Memoize results from the fast predicate matcher This gains another 15% for the parser, again with a very simple change that has no impact if the fast predicate matcher fails to work. --- src/xact.cc | 17 ++++++++++++++++- src/xact.h | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'src/xact.h') diff --git a/src/xact.cc b/src/xact.cc index 330ad38a..a84b4dca 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -597,10 +597,25 @@ void auto_xact_t::extend_xact(xact_base_t& xact) bool matches_predicate = false; if (try_quick_match) { try { + bool found_memoized_result = false; + if (! memoized_results.empty()) { + std::map::iterator i = + memoized_results.find(initial_post->account->fullname()); + if (i != memoized_results.end()) { + found_memoized_result = true; + matches_predicate = (*i).second; + } + } + // Since the majority of people who use automated transactions simply // match against account names, try using a *much* faster version of // the predicate evaluator. - matches_predicate = post_pred(predicate.get_op(), *initial_post); + if (! found_memoized_result) { + matches_predicate = post_pred(predicate.get_op(), *initial_post); + memoized_results.insert + (std::pair(initial_post->account->fullname(), + matches_predicate)); + } } catch (...) { DEBUG("xact.extend.fail", diff --git a/src/xact.h b/src/xact.h index 07f9a6c7..c819b2a0 100644 --- a/src/xact.h +++ b/src/xact.h @@ -148,6 +148,8 @@ public: predicate_t predicate; bool try_quick_match; + std::map memoized_results; + auto_xact_t() : try_quick_match(true) { TRACE_CTOR(auto_xact_t, ""); } -- cgit v1.2.3