From cf5c5f6a492bb92b25aeb880e46e9df2560a4c2e Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Tue, 1 Mar 2011 11:22:17 -0800 Subject: add caching for parsed config templates * this improves backend performance by ~15% in, e.g., "load" (w/o commit) and "show". * this is only temporary and eventually caching should be done at higher level for better performance, and that will require config path abstraction. --- src/cstore/unionfs/cstore-unionfs.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/cstore/unionfs/cstore-unionfs.cpp b/src/cstore/unionfs/cstore-unionfs.cpp index b42c8f8..50aefb5 100644 --- a/src/cstore/unionfs/cstore-unionfs.cpp +++ b/src/cstore/unionfs/cstore-unionfs.cpp @@ -415,18 +415,33 @@ UnionfsCstore::tmpl_node_exists() return (b_fs_exists(tmpl_path) && b_fs_is_directory(tmpl_path)); } +typedef Cstore::MapT > ParsedTmplCacheT; +static ParsedTmplCacheT _parsed_tmpl_cache; + /* parse template at current tmpl_path and return an allocated Ctemplate * pointer if successful. otherwise return 0. */ Ctemplate * UnionfsCstore::tmpl_parse() { + b_fs::path tp = tmpl_path / C_DEF_NAME; + if (!b_fs_exists(tp) || !b_fs_is_regular(tp)) { + // invalid + return 0; + } + + ParsedTmplCacheT::iterator p = _parsed_tmpl_cache.find(tp.file_string()); + if (p != _parsed_tmpl_cache.end()) { + // found in cache + return (new Ctemplate(p->second)); + } + + // new template => parse tr1::shared_ptr def(new vtw_def); vtw_def *_def = def.get(); - b_fs::path tp = tmpl_path / C_DEF_NAME; - if (_def && b_fs_exists(tp) && b_fs_is_regular(tp) - && parse_def(_def, tp.file_string().c_str(), 0) == 0) { - // succes + if (_def && parse_def(_def, tp.file_string().c_str(), 0) == 0) { + // succes => cache and return + _parsed_tmpl_cache[tp.file_string()] = def; return (new Ctemplate(def)); } return 0; -- cgit v1.2.3