Commits

dirkbaechle  committed afe3a1f

- additional speedup by caching subst() calls for global vars in an Environment

  • Participants
  • Parent commits d907d2a
  • Branches reduced_memory_updated

Comments (0)

Files changed (1)

File src/engine/SCons/Environment.py

 semi_deepcopy = SCons.Util.semi_deepcopy
 semi_deepcopy_dict = SCons.Util.semi_deepcopy_dict
 
+cache_env_subst = 1 #None
+
 # Pull UserError into the global name space for the benefit of
 # Environment().SourceSignatures(), which has some import statements
 # which seem to mess up its ability to reference SCons directly.
         self._init_special()
         self.added_methods = []
         #self._memo = {}
+        self.gvars_cache = [{}, {}, {}]
 
     def _init_special(self):
         """Initial the dispatch tables for special handling of
     def lvars(self):
         return {}
 
-    def subst(self, string, raw=0, target=None, source=None, conv=None, executor=None):
+    def subst(self, string, raw=0, target=None, source=None, conv=None, executor=None,
+              allow_caching=True):
         """Recursively interpolates construction variables from the
         Environment into the specified string, returning the expanded
         result.  Construction variables are specified by a $ prefix
         may be surrounded by curly braces to separate the name from
         trailing characters.
         """
+        global cache_env_subst
+        
         gvars = self.gvars()
+        if (cache_env_subst and SCons.Node.FS.Save_Strings and 
+            allow_caching and not conv and isinstance(string, str)):
+            # Try to find string in cache
+            try:
+                string = self.gvars_cache[raw][string]
+            except:
+                res = SCons.Subst.scons_subst(string, self, raw, target, source, gvars, {}, conv)
+                self.gvars_cache[raw][string] = res
+                string = res
         lvars = self.lvars()
         lvars['__env__'] = self
         if executor:
             lvars.update(executor.get_lvars())
+        
         return SCons.Subst.scons_subst(string, self, raw, target, source, gvars, lvars, conv)
 
     def subst_kw(self, kw, raw=0, target=None, source=None):
         """
         if __debug__: logInstanceCreation(self, 'Environment.Base')
         self._memo = {}
+        self.gvars_cache = [{}, {}, {}]
         self.fs = SCons.Node.FS.get_default_fs()
         self.ans = SCons.Node.Alias.default_ans
         self.lookup_list = SCons.Node.arg2nodes_lookups