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.
This commit is contained in:
John Wiegley 2009-11-14 04:29:53 -05:00
parent e3064b9520
commit d89c60f49c
2 changed files with 18 additions and 1 deletions

View file

@ -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<string, bool>::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<string, bool>(initial_post->account->fullname(),
matches_predicate));
}
}
catch (...) {
DEBUG("xact.extend.fail",

View file

@ -148,6 +148,8 @@ public:
predicate_t predicate;
bool try_quick_match;
std::map<string, bool> memoized_results;
auto_xact_t() : try_quick_match(true) {
TRACE_CTOR(auto_xact_t, "");
}